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

1, Experimental purpose

1. Understand and master the assembly source program of more than 8086 logic segments

2. Understand and skillfully apply flexible addressing methods

3. Understand the essence of loop in programming language through the use of assembly instruction loop, and master its correct use in nested loop

4. Master the method of debugging 8086 assembler with debug

2, Experimental content

1. Experimental task 1

Experimental task 1-1

 task1_1.asm

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

In debug, it will be executed until the end of line17 and before line19,

① Record: 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_.

Experimental task 1_ two

task1_2.asm

assume ds:data, cs:code, ss:stack
data segment
db 4 dup(0) ; Four byte units are reserved, and the initial value is 0
data ends
stack segment
db 8 dup(0) ; 8 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, 8 ; Set stack top
mov ah, 4ch
int 21h
code ends
end start

In debug, it will be executed until the end of line17 and before line19,

  ① 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_.

Experimental task 1_ three

task1_3.asm

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, it will be executed until the end of line17 and before line19,

① Record: 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_.

Experimental task 1_ four

task1_4.asm

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, it will be executed until the end of line9 and before line11,

 

  ① Record: 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_.

 

Experimental task 1_ five

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_ 16*[N/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.

task1_1 cannot be executed correctly

task1_2. It cannot be executed correctly

  task1_3. It cannot be executed correctly

  task1_4. It can be executed correctly

 

  Reason: after it is changed to end, the execution starts from the program code header by default, while the program header of 123 is not a program segment. If it is executed directly from the header, an error will occur.

2. Experimental task 2

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

assume cs:code
code segment
    mov ax,0b800h
    mov ds,ax
    mov ax,0403h
    mov bx,0f00h

    mov cx,160
s:  mov [bx],ax
    inc bx
    inc bx
    loop s
   
    mov ax,4c00h
    int 21h
code ends
end

  3. Experimental task 3

task3.asm

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 cx,10
s: mov dx,0
mov ax,data1
mov ds,ax
add dl,[bx]

mov ax,data2
mov ds,ax
add dl,[bx]

mov ax,data3
mov ds,ax
add [bx],dl

inc bx
loop s

mov ah,4ch
int 21h

code ends
end start

Before adding:

 

After addition:

 

4. Experimental task 4

 task4.asm

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 ax,data2
    mov ss,ax
    mov sp,16
    mov bx,0
    mov cx,8
s:  push [bx]
    add bx,2
    loop s

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

Before program execution:

After program execution:

5. Experimental task 5

 task5.asm

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.

 

 

  The function of line19 in the source code is to use the and operation to turn lowercase uist into uppercase

Modify the value of 5 byte units in line4, reassemble, link, run and observe the results.  

db 2,3,4,5,6
--> Change to:
db 5 dup(2) or db 5 dup(5)

Based on observation, analysis and guess, the numerical function here is to control the color of NUIST

6. Experimental task 6

task6.asm

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

  7. Experimental task 7

 task7.asm

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 cx, 5
years:
    mov ax, [bx]
    mov es:[bp], ax
    mov ax, [bx+2]
    mov es:[bp+2], ax
    add bx, 4
    add bp, 10h
    loop years

    mov bp, 5
    mov cx, 5
income:
    mov ax, [bx]
    mov es:[bp], ax
    add bx, 2
    add bp, 10h
    loop income

    mov cx, 5
    mov bp, 10
people:
    mov ax, [bx]
    mov es:[bp], ax
    add bx, 2
    add bp, 10h
    loop people

    mov cx, 5
    mov bp, 5
averageincome:
    mov ax, es:[bp]
    mov bl, es:[bp+5]
    div bl
    mov es:[bp+8], al
    add bp,10h
    loop averageincome

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

 

Posted by 8ball on Mon, 08 Nov 2021 13:05:09 -0800