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

4, Experimental conclusion

1. Experimental task 1

Task 1-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

(2)task1_1. Screenshot after debugging to the end of line17 and before line19:

(3) 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:

(1) 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

(2)task1_2. Screenshot of observing the values of registers DS, CS and SS at the end of debugging to line17 and before line19:

(3) Question answer:
① In debug, it will be executed until the end of line17 and before line19. At this time, 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.

Tasks 1-3:

(1) 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
end start

(2)task1_3. Screenshot of observing the values of registers DS, CS and SS at the end of debugging to line17 and before line19:

(3) Question answer:
① In debug, it will be executed until the end of line17 and before line19. At this time, 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__.

Tasks 1-4:

(1) 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

(2)task1_4. Screenshot of observing the values of registers DS, CS and SS at the end of debugging to line17 and before line19:

(3) 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__, Segment address of stack
Yes__ 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 16*Math.ceil(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, 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.
task1_4.asm can run normally, because if start is not specified, it will run from the beginning of the program code by default, and Task1_ 1~1_ The code header of 3 is not a program segment. If it is executed directly from the header, an error will occur.

  • end start indicates that the entry of the program is at the label start.

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.
(1) Assembly source code:

assume cs:code
code segment
start:mov ax,0b800h
         mov ds,ax
         mov bx,0f00h
         mov cx,80
         mov dx,0403h
      s:mov ds:[bx],dx
         add bx,2
         loop s

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

(2) Screenshot of operation results:

3. Experimental task 3

It is known that the 8086 assembly source program task3.asm code fragment is as follows.
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:
   ; ×××
code ends
end start

requirement:
① The programming adds the data of logical segment data1 and logical segment data2 in turn, and the results are saved in logical segment data3.
② Load, disassemble and debug in debug. Before and after the data items are added in turn, view the three logical segments data1 respectively,
Confirm that the memory space corresponding to data2 and data3 is added one by one to ensure that the result exists in the logical segment data3.
(1) 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 ax,data1
   mov ds,ax
   mov bx,0
   mov cx,10
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

(2) Screenshot of loading, disassembling and debugging in debug:

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

And, after adding in turn, view the debug command and the original value of the memory space data corresponding to the logical segments data1, data2 and data3
Screenshot:

  • Before adding:

  • After addition:

4. Experimental task 4

It is known that the 8086 assembly source program task4.asm code fragment is as follows.
requirement:
① Complete the program to store the eight word data in logical segment data1 in reverse order in logical segment b.
② After assembly and connection, load the program in debug and run it to line15. Before the program exits, use the d command to view the data corresponding to data segment data2
Memory space, confirm whether the subject requirements are met.

(1) 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(?)
data2 ends

code segment
start:
    mov ax,data1
    mov ds,ax
    mov ax,data2
    mov ss,ax
    mov sp,16   ;8 Word
    mov bx,0
    mov cx,8
s :push ds:[bx]
     add bx,2
     loop s
    mov ah, 4ch
    int 21h
code ends
end start

(2) Load, disassemble and debug screenshots in debug

It is required to give a screenshot of the memory space corresponding to data segment data2 by using the d command before the program exits.

  • Before storage:

  • Before the program exits, use the d command to view the memory space corresponding to data segment data2:

Experimental task 5

Use any text editor to enter the assembly source program task5.asm.
(1) task5.asm source code:
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

(2) Screenshot of operation results:

(3) Use the debug tool to debug the program, and use the g command to execute it once before the program returns (i.e. after the execution of ine25 and line27)
Screenshot before execution:

(4) What is the function of line19 in the source code?
AL and DF(1101 1111): clear the third digit on the left to 0.
(5) What is the purpose of the byte data in the data segment line4 in the source code?
Operation results after modifying line4 to db 5 dup(2):

Result after modification to db 5 dup(5):

db is a pseudo instruction that defines the type of variable as byte type, that is, each variable occupies a storage unit
db 2,3,4,5,6 is used to allocate a storage unit for each number after db.

Experimental task 6

It is known that the 8086 assembly source program task6.asm code fragment is as follows.
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 ah, 4ch
   int 21h
code ends
end start

requirement:
① Complete the program and change the first word of each line in the data section from uppercase to lowercase.
② Load the program in debug, disassemble it, and check the memory space corresponding to the data segment with the d command before exiting line13, and confirm that each
The first word of the line has been changed from uppercase - > lowercase.

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

(2) Screenshot of loading, disassembling and debugging in debug:

It is required to give a screenshot of the memory space corresponding to the data segment data by using the d command before the program exits.

Experimental task 7

requirement:
① Complete the program, realize the title requirements, and write the year, income, number of employees and per capita income into the table section in a structured way.
In the table, each row of data occupies 16 bytes in the logical segment table, and the byte size of each data is allocated as follows. Interim, between data
Space spacing.

(1) task7.asm 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 cx,5
    mov si,0
    mov bx,0
s: mov ax,[si]
    mov es:[bx],ax
    mov ax,[si+2]
    mov es:[bx+2],ax
    add bx,10h
    add si,4
    loop s   ;particular year

   mov cx,5
   mov si,20
   mov bx,5
s1:mov ax,[si]
    mov es:[bx],ax
    mov ax,0
    mov es:[bx+2],ax
    add bx,16
    add si,2
    loop s1;  ;income

   mov cx,5
   mov si,30
   mov bx,10
s2:mov ax,[si]
     mov es:[bx],ax
     add bx,16
     add si,2
     loop s2   ;Number of employees

   mov cx,5
   mov si,5
s3:mov ax,es:[si]
     mov bl,es:[si+5]
     div bl
     mov es:[si+8],al
     add si,16
     loop s3   ;Per capita income
    mov ah, 4ch
    int 21h
code ends
end start

(2) Commissioning screenshot:

(3) View the screenshot of the original data information of the 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 that the information is
No structured write to specified memory as required

It can be seen from the d command in the figure above that the information has been structurally written to the specified memory as required.

Posted by jrmontg on Sat, 06 Nov 2021 02:43:23 -0700