Experiment 2 compilation and debugging of assembly source program of multiple logic segments

1. Experimental task 1

1_1)task1_1.asm source code:

assume ds:data, cs:code, ss:stack

data segment
    db 16 dup(0) ;16 byte units are reserved, and the initial values are 0
data ends

stack segment
    db 16 dup(0) ;16 byte units are reserved, and the initial values are 0
stack ends
code segment
start:
    mov ax, data
    mov ds, ax

    mov ax, stack
    mov ss, ax
    mov sp, 16 ;Set stack top

    mov ah, 4ch
    int 21h
code ends
end start

task1_1 screenshot before the end of line17 and line19

  Compile and connect the source program

 

debug use the d command to check that the memory unit pointed to by the current CS:IP is 076C:0000, and then use the u command to disassemble the corresponding memory to get the address of the target statement as 076C:000A

Use the g command to execute after line17 and before line19

 

Question answer

① In debug, execute until the end of line17 and before line19. Record this time: register (DS) = 076A, register (SS) = 076B, register (CS) = 076C

② Assuming that the segment address of the code segment is X after the program is loaded, the segment address of the data segment is X-2 and the segment address of the stack is X-1

1_2)task1_2.asm source code

assume ds:data, cs:code, ss:stack data segment db 4 dup(0) data ends stack segment db 8 dup(0) stack ends code segment start: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 8 mov ah, 4ch int 21h code ends end start

task1_2. After debugging to the end of line17 and before line19, observe the screenshot of register DS, CS and SS values

The process is consistent with task 1

 

  You can see that the target command address is 076C:000A

  Use the g command to execute after line17 and before line19

 

Question answer

① In debug, execute until the end of line17 and before line19. Record this time: register (DS) = 076A, register (SS) = 076B, register (CS) = 076C

② Assuming that the segment address of the code segment is X after the program is loaded, the segment address of the data segment is X-2 and the segment address of the stack is X-1

1_3)task1_3.asm source code:

assume ds:data, cs:code, ss:stack

data segment
    db 20 dup(0)
data ends

stack segment
    db 20 dup(0)
stack ends
code segment
start:
    mov ax, data
    mov ds, ax

    mov ax, stack
    mov ss, ax
    mov sp, 20

    mov ah, 4ch
    int 21h
code ends
end start

task1_3. Screenshot of the values of registers DS, CS and SS before the end of debugging to line17 and line19

Use the g command to execute after line17 and before line19

Question answer

① In debug, execute until the end of line17 and before line19. Record this time: register (DS) = 076A, register (SS) = 076C, register (CS) = 076E

② Assuming that the segment address of the code segment is X after the program is loaded, the segment address of the data segment is X-4 and the segment address of the stack is X-2

1_4)task1_4.asm source code:

assume ds:data, cs:code, ss:stack
code segment
start:
    mov ax, data
    mov ds, ax

    mov ax, stack
    mov ss, ax
    mov sp, 20

    mov ah, 4ch
    int 21h
code ends

data segment
    db 20 dup(0)
data ends

stack segment
    db 20 dup(0)
stack ends
end start

task1_4. Screenshot of the values of registers DS, CS and SS before debugging to line9 and line11

Question answer

① In debug, execute until the end of line9 and before line11. Record this time: register (DS) = 076C, register (SS) = 076E, register (CS) = 076A

② Assuming that the segment address of the code segment is X after the program is loaded, the segment address of the data segment is X+2 and the segment address of the stack is X+4

1_ 5) Based on the practice and observation of the above four experimental tasks, summarize and answer:

① For the segment defined below, after the program is loaded, the actual memory space allocated to the segment is   ([N/16]+1)*16

xxx segment
    db N dup(0)
xxx ends

② If the program Task1_ 1.asm, task1_ 2.asm, task1_ 3.asm, task1_ 4. In ASM, if the pseudo instruction end start is changed to end, which program can still be executed correctly. The reasons are analyzed and explained in combination with the conclusions obtained from practical observation.

A: only task1_4.asm can still be executed correctly. end start informs the compiler that the entry of the program is at start. Removing start may lead to positioning errors.

With Task1_ 1. Take ASM as an example:

  At this time, the CS:IP actually points to the data segment. The u command disassembly finds that the value at CS:IP is the 0 reserved for the data segment, and the program executes it as an instruction, which is obviously wrong

2. Experimental task 2

Assembly source code:

assume cs:code

code segment
    mov ax, 0b800h
    mov ds, ax
    mov bx, 0f00h
    mov cx, 50h    ;Cycle 80 times 
    mov ax, 0403h
s:  mov ds:[bx], ax
    add bx, 2       
    loop s

    mov ah, 4ch
    int 21h
code ends
end 

Screenshot of operation results

Compile, connect and run the source code

3. Experimental task 3

Complete assembly source code

assume cs:code
data1 segment
    db 50, 48, 50, 50, 0, 48, 49, 0, 48, 49 ; ten numbers
data1 ends

data2 segment
    db 0, 0, 0, 0, 47, 0, 0, 47, 0, 0       ; ten numbers
data2 ends

data3 segment
    db 16 dup(0)
data3 ends

code segment
start:
    mov bx 0
    mov ax data1
    mov ds ax
    mov cx 0ah
s:  mov ax, [bx]    
    add ax, [bx+10h]    ;data1 and data2 Data addition of
    mov [bx+20h], ax    ;put to data3 In paragraph
    inc bx
    loop s

    mov ah, 4ch
    int 21h
code ends
end start

Load, disassemble and debug screenshots in debug  

Before adding data items in turn, check the debug command and screenshot of the original value of memory space data corresponding to logical segments data1, data2 and data3

 

  After adding in sequence, view the debug command and screenshot of the original value of memory space data corresponding to logical segments data1, data2 and data3

 

  You can find the perfect addition and save it

  4. Experimental task 4

Complete assembly source code

assume cs:code

data1 segment
    dw 2, 0, 4, 9, 2, 0, 1, 9
data1 ends 

data2 segment
    dw 8 dup(0)
data2 ends

code segment
start:
    mov ax,data1
    mov ds,ax
    mov ax,data2
    mov ss,ax
    mov sp,16
    mov bx,0
    mov cx,8
s:  mov ax,[bx]
    push ax
    add bx,2
    loop s

    mov ah, 4ch
    int 21h
code ends
end start

Load, disassemble and debug screenshots in debug  

 

  Before the program exits, use the d command to view a screenshot of the memory space corresponding to the data segment data2

 

  5. Experimental task 5

task5.asm source code

assume cs:code, ds:data
data segment
        db 'Nuist'
        db 2, 3, 4, 5, 6
data ends

code segment
start:
        mov ax, data
        mov ds, ax

        mov ax, 0b800H
        mov es, ax

        mov cx, 5
        mov si, 0
        mov di, 0f00h
s:      mov al, [si]
        and al, 0dfh
        mov es:[di], al
        mov al, [5+si]
        mov es:[di+1], al
        inc si
        add di, 2
        loop s

        mov ah, 4ch
        int 21h
code ends
end start

Screenshot of operation results

Use the debug tool to debug the program, and use the g command to execute the screenshot before the program returns (i.e. after ine25 and before line27)

What is the function of line19 in the source code?

A: the function is to change lowercase letters into uppercase letters

What is the purpose of the byte data in the data segment line4 in the source code?

A: determine the color of the output letters

6. Experimental task 6

task6.asm source code

assume cs:code, ds:data

data segment
    db 'Pink Floyd      '
    db 'JOAN Baez       '
    db 'NEIL Young      '
    db 'Joan Lennon     '
data ends

code segment
start:
   mov ax,data
   mov ds,ax
   mov bx,0
   mov cx,4
s: mov al,ds:[bx]
   or al,20h
   mov ds:[bx],al
   add bx,16
   loop s

   mov ah, 4ch
   int 21h
code ends
end start

Load, disassemble and debug screenshots in debug

Before the program exits, use the d command to view a screenshot of the memory space corresponding to the data segment data

Run until the program exits

Then view the memory space corresponding to the data segment data

 

  You can see that the first uppercase letter of each line is replaced by lowercase

7. Experimental task 7

  task7.asm source code

assume cs:code, ds:data, es:table 
data segment 
    db '1975', '1976', '1977', '1978', '1979' 
    dd 16, 22, 382, 1356, 2390 
    dw 3, 7, 9, 13, 28 
data ends
 
table segment 
    db 5 dup( 16 dup(' ') )  
table ends 

code segment 
start:
    mov ax,data
    mov ds,ax
    mov ax,table
    mov es,ax
    
    mov bx,0
    mov bp,0
    mov cx,5
s:  
    mov ax,ds:[bx]
    mov dx,ds:[bx+2]
    mov es:[bp],ax
    mov es:[bp+2],dx
    mov byte ptr es:[bp+4],' '
    add bx,4
    add bp,10h
    loop s 

    mov bp,0
    mov cx,5
s1: mov ax,ds:[bx]
    mov dx,ds:[bx+2]
    mov es:[bp+5],ax
    mov es:[bp+7],dx
    mov byte ptr es:[bp+9],' '
    add bx,4
    add bp,10h
    loop s1
    
    mov bp,0
    mov cx,5
s2: mov ax,ds:[bx]
    mov es:[bp+0ah],ax
    mov byte ptr es:[bp+0ch],' '
    add bx,2
    add bp,10h
    loop s2

    mov bp,0
    mov cx,5
s3: mov ax,es:[bp+5]
    mov dx,es:[bp+7]
    div word ptr es:[bp+0ah]
    mov es:[bp+0dh],ax
    mov byte ptr es:[bp+0fh],' '
    add bp,10h
    loop s3
    
    mov ah, 4ch 
    int 21h 
code ends 
end start

View screenshot of original data information of table segment

Run in debug until the program exits, use the d command to view the screenshot of the memory space corresponding to the table segment, and confirm whether the information is structurally written to the specified memory as required

 

  You can see the successful write

 

Posted on Sun, 07 Nov 2021 23:10:54 -0500 by cloudzilla