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

Posted by c_shelswell on Sat, 06 Nov 2021 13:10:57 +0100

1. Experimental task 1

  • Task 1-1

To program task1_1.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.

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

 

 

 

① 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-2_, The segment address of stack is_ X-1_.

 

 

  • Task 1-2

To program task1_2.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.

 

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

 

 

 

① 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-2_, The segment address of stack is_ X-1_.

 

  • Task 1-3

To program task1_3.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.

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

 

 

 

① 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_ X-4_, The segment address of stack is_ X-2_.

 

 

  • Tasks 1-4

To program task1_4.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.

 

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

 

 

 

① 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_ X+2_, The segment address of stack is
_X+4_.

 

 

  • 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/16) rounding * 16_.

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

 

Only task1_4 can be executed.

Because start and end start appear together, otherwise the program will be executed from the beginning, and only Task1_ The first line is the code snippet.

 

2. Experimental task 2
Write an assembly source program to realize 160 consecutive bytes to memory units b800:0f00 ~ b800:0f9f, and fill hexadecimal numbers repeatedly in turn
According to 03 04.

assume cs:code
code segment
start:
    mov ax,0b800h
    mov ds,ax
    mov bx,0f00h
    mov cx,80
s:  mov [bx],0403h
    add bx,2
    loop s
    mov ax,4c00h
    int 21h
code ends
end start

 

 

 

3. Experimental task 3

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 ax,data1
    mov ds,ax
    mov cx,16
    mov bx,0
s:  
    mov al,ds:[bx]
    add al,ds:[bx+16]
    mov ds:[bx+32],al
    inc bx
    loop s

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

 

 

 

The first three data memory spaces:

 

 

 

  After operation:

 

 

 

4. Experimental task 4

assume cs:code

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

data2 segment
    dw 8 dup(?)
data2 ends

code segment
start:
    mov ax,data1
    mov ds,ax
    mov bx,0
    mov si,30
    mov cx,8
s: mov ax,[bx]
    mov [si],ax
    sub si,2
    add bx,2
    loop s
    mov ah, 4ch
    int 21h
code ends
end start

 

 

 

5. Experimental task 5

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
  • Assemble and link the program to get the executable file, run and observe the results.

 

 

  • Use the debug tool to debug the program and observe the results before the program returns, that is, after line25 and before line27.

 

 

  • What is the function of line19 in the source code?

Convert letters to uppercase letters

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

Sets the color of the output character

 

6. Experimental task 6

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: or byte ptr [bx],32
   add bx,16
   loop s
   mov ah, 4ch
   int 21h
code ends
end start

 

 

7. Experimental task 7

assume cs:code, ds:data, es:table

data segment
    db '1975', '1976', '1977', '1978', '1979' 
    dw  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 si,20
    mov cx,5

s:  mov ax,ds:[bx]
    mov es:[bp],ax
    mov ax,ds:[bx+2]
    mov es:[bp+2],ax

    mov ax,ds:[si]
    mov es:[bp+5],ax
    mov word ptr es:[bp+7],0

    mov ax,ds:[si+10]
    mov es:[bp+10],ax

    mov ax,ds:[si]
    mov dl,ds:[si+10]
    div dl
    mov es:[bp+13],al
    mov byte ptr es:[bp+14],0

    add bx,4
    add bp,16
    add si,2

    loop s

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