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

Experimental task 1
 
Task 1-1
  task1_1.asm source code
assume ds:data, cs:code, ss:stack

data segment
    db 16 dup(0)
data ends

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

    mov ax, stack
    mov ss, ax
    mov sp, 16

    mov ah, 4ch
    int 21h
code ends
end start
  
  task1_1 screenshot before the end of line17 and 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_ X-0002H___, The segment address of stack is__ X-0001H__.

 
 
Task 1-2

Task 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

  

 

 

Question answer

① in debug, execute until the end of line17 and before line19, and 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_ X-0002H___,   The segment address of stack is__ X-0001H__.

 

 

Task 1-3

Task 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

 

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

  

 

 

Question answer

① in debug, execute until the end of line17 and before line19, and 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_ X-0004H___,   The segment address of stack is__ X-0002H__.

 

Tasks 1-4

Task 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. After debugging to the end of line17 and before line19, observe the screenshot of register DS, CS and SS values

  

 

 

Question answer

① in debug, execute until the end of line9 and before line11, and 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__ X+0002H__,   The segment address of stack is_ X+0004H___.

 

 

Tasks 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 bytes _.

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.

Answer: task1_4 can be executed correctly. Because after changing to end, the program executes from the beginning, except task1_4. Other programs are not executed from scratch.

 

Experimental task 2
 
Assembly source code
assume cs:code 
data segment
    db 80 dup(03h,04h)
data ends

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

    mov ax,0b800h
    mov es,ax
    mov bx,0f00h
    mov bp,0
    
    mov cx,160
s:  mov ax,[bp]
    mov es:[bx],ax
    inc bx
    inc bp
    loop s

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

 

Screenshot of operation results
  

 

Experimental task 3
Complete assembly source code
assume cs:code
data1 segment
    db 504850500484904849 ; ten numbers
data1 ends

data2 segment
    db 000047004700       ; ten numbers
data2 ends

data3 segment
    db 16 dup(0)
data3 ends

code segment
start:
    mov ax,data3
    mov ds,ax
    mov ax,data1
    mov es,ax

    mov cx,10
    mov bx,0
s1: mov al,es:[bx]
    add [bx],al
    inc bx
    loop s1

    mov ax,data2
    mov es,ax

    mov cx,10
    mov bx,0
s2: mov al,es:[bx]
    add [bx],al
    inc bx
    loop s2

    mov ah,41h
    int 21h

code ends
end start

 

Load, disassemble and debug screenshots in debug
Screenshot of data1 before adding
    

Screenshot of data2 before adding:

    

  Screenshot of data3 before adding:

    

Screenshot of data1 after addition:

    

Screenshot of data2 after addition:

     

Screenshot of data3 after addition:

     

 

 

Experimental task 4
Complete assembly source code
assume cs:code

data1 segment
    dw 20492019
data1 ends 

data2 segment
    dw 8 dup(?)
data2 ends

code segment
start:
    mov ax,data1
    mov ds,ax
    mov ax,data2
    mov es,ax
    mov sp,16

    mov bx,0
    mov cx,8
s1: push [bx]
    add bx,2
    loop s1

    mov bx,0
    mov cx,8
s2: pop [bx]
    add bx,2
    loop s2

    mov bx,0
    mov cx,8
s3: mov ax,[bx]
    mov es:[bx],ax
    add bx,2
    loop s3

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

 

Load, disassemble and debug screenshots in debug
  

 

Experimental task 5
task5.asm source code
assume cs:code, ds:data
data segment
        db 'Nuist'
        db 23456
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?

Answer: line19 is used to sum the Ascll code of "Nuist" with the hexadecimal number dfh bit by bit

 

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

A: the byte data of line4 in the data section of the source code is used to control the display color

  
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 cx,4
    mov bx,0
s:  mov dx,[bx]
    mov ax,dx
    add al,32
    mov [bx],ax
    add bx,16
    loop s

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

 

Load, disassemble and debug screenshots in debug
  
 
 
Experimental task 7
task7.asm source code
assume cs:code, ds:data, es:table

data segment
    db '1975''1976''1977''1978''1979' ;20 bytes per line
    dw  162238213562390
    dw  3791328 
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 si,0
    mov bp,0
    mov di,0
    

    mov cx,5
s:  mov ax,[bx+si]              ;1975
    mov es:[bp+di],ax    
    add si,2
    add di,2
    mov ax,[bx+si]    
    mov es:[bp+di],ax 

    mov ax,0                    ;[sp]0016[sp]
    add ax,cx
    add ax,cx
    add ax,8
    add si,ax                   ;Here to implement y=8+2n To track this specific si How much,among n by cx Value of
    add di,2
    mov ax,[bx+si]              ;ax Store 16 bit divisor
    mov dl,32
    mov dh,00h
    mov es:[bp+di],dx
    add di,2
    mov dl,00h
    mov dh,al
    mov es:[bp+di],dx
    add di,2
    mov dl,ah
    mov dh,32
    mov es:[bp+di],dx

    add si,10
    add di,2
    mov dx,[bx+si]              ;dl Stored divisor
    mov es:[bp+di],dx

    add di,2
    div dl                      ;al Depositors, ah Deposit remainder
    mov dl,32
    mov dh,al
    mov es:[bp+di],dx
    add di,2
    mov dl,00h
    mov dh,32
    mov es:[bp+di],dx

    add bx,4                    ;Next cycle initialization
    add bp,16
    mov si,0
    mov di,0

    loop s

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

 

Debug screenshot
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
    

 

Added by thedotproduct on Thu, 04 Nov 2021 07:42:15 +0200