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
Task 1_ 1:
task1_1. 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

 

Commissioning screenshot:

  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-2_, The segment address of stack is_ X-1_.
Task 1_ 2:
task1_2. 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
Commissioning screenshot:
 

  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-2___, The segment address of stack is_ X-1___.
Task 1_ 3:
task1_3. 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

Commissioning screenshot:

  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_ X-4___, The segment address of stack is_ X-2___.
Task 1_ 4:
task1_4 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
Commissioning screenshot:

  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_ X+2___, The segment address of stack is_ X+4___.
Task 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]*16 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. Analyze and explain the conclusions obtained from practical observation

  After modification, program 123 cannot be executed correctly, and program 4 can still be executed correctly, because deleting start does not indicate the entry of the program. By default, the execution starts from the first line of the program, only Task1_ The beginning of 4 can be executed.

2. Experimental task 2

Assembly source code:
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
Screenshot of operation results:

3. Experimental task 3

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 ax,data1
   mov ds,ax
   mov bx,0
   mov cx,0ah
s:mov ax,ds:[bx]
   add ax,ds:[bx+10h]
   mov ds:[bx+20h],ax
   inc bx
   loop s

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

Before adding:

After addition:

4. Experimental task 4

Assembly source code:
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 bx, 0
    mov ax, data1
    mov ds, ax
    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 ah, 4ch
    int 21h
code ends
end start

  Commissioning screenshot:

 

  Screenshot after program running:

  5. Experimental task 5

  task5 source code:
assume cs:code, ds:data
data segment
        db 'Nuist'
        db 5 dup(2)
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

  Operation results:

  Commissioning screenshot:

The function of line19 in the source code is to convert lowercase to uppercase

Screenshot after modification:

The function of numerical value is to determine the color of characters

6. Experimental task 6

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

Commissioning screenshot:

  View memory space:

  7. Experimental task 7

Source code:

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
average:
    mov ax, es:[bp]
    mov bl, es:[bp+5]
    div bl
    mov es:[bp+8], al
    add bp,10h
    loop average

    mov ah, 4ch
    int 21h
code ends
end start
Data information of logical segment table at the beginning:

After structured data storage:

 

 

 

  3, Experimental summary

Through this experiment, I have a further understanding of the structure of assembly source program, can clarify the meaning of different logic segments, strengthen the application of addressing mode, and practice the usage of assembly instructions loop and div.

 

Added by iamyespee on Tue, 09 Nov 2021 07:40:41 +0200