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

Posted by chetanrakesh on Mon, 08 Nov 2021 10:02:10 +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.

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

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

 

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

①   In debug, execute until the end of line17 and before line19. 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)*16___.

② 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.

Answer: task1_4.asm can operate normally. If the pseudo instruction end start is changed to end, it means that the program entry is not indicated. The first three codes start with a data segment, and only the fourth is a code segment.

 

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

start:

         mov ax,0b800h

         mov ds,ax

         mov bx,0f00h

         mov cx,80

         mov dx,0403h

s:       mov ds:[bx],dx

         inc bx

         inc bx

         loop s

         mov ah,4ch

         int 21h

code ends

end start

experimental result

 

3. Experimental task 3

It is known that the 8086 assembly source program task3.asm code fragment is as follows.

① The programming adds the data of logical segment data1 and logical segment data2 in turn, and the results are saved in logical segment data3.

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
         mov ax,data1
         mov ds,ax
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

② Load, disassemble and debug in debug. Before and after the data items are added in turn, check the memory space corresponding to the three logical segments data1, data2 and data3 respectively. After adding them one by one, ensure that the results exist in the logical segment data3.

Before addition

After addition

 

4. Experimental task 4

It is known that the 8086 assembly source program task4.asm code fragment is as follows.

① Complete the program to store the eight word data in logical segment data1 in reverse order in logical segment b.

assume cs:code 
data1 segment 
    dw 2, 0, 4, 9, 2, 0, 1, 9 
data1 ends 
data2 segment 
    dw 8 dup(0) 
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    

② After assembly and connection, load the program in debug and run it to line15. Before the program exits, use the d command to check the memory space corresponding to data segment data2 to confirm whether the subject requirements are met.

Before reverse order

After reverse order

5. Experimental task 5

Use any text editor to enter the assembly source program task5.asm.

Read the source program, theoretically analyze the functions of the source code, especially line15-25, what are the functions realized by the loop, and understand the functions of each instruction line by line

Assemble and link the program to get the executable file, run and observe the results.

Use the debug tool to debug the program. Before the program returns, that is, after line25 is executed and before line27 is executed, observe the results. What is the role of line19 in the source code?

 

A: change lowercase letters to uppercase letters

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

 

 

A: change the font color

 

6. Experimental task 6

It is known that the 8086 assembly source program task6.asm code fragment is as follows.

① Complete the program and change the first word of each line in the data section from uppercase to lowercase.

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

② Load the program in debug, disassemble it, and check the memory space corresponding to the data section with the d command before exiting line13. Confirm that the first word in each line has changed from uppercase to lowercase.

 

 

  7. Experimental task 7

Problem scenario description:

The basic information of Power idea from 1975 to 1979 is as follows:

 

These data have been defined in the logical segment data (line4-6) of program task7.asm.

① 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. During the period, the data is separated by spaces.

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  ;Number of cycles
	mov si,0
	mov bx,0  ;Number of rows
s1: 
	mov ax,[si]
	mov es:[bx],ax
	add si,2
	mov ax,[si]
	mov es:[bx+2],ax
	add bx,16
	add si,2
	loop s1  
	mov cx,5
	mov si,20
	mov bx,5  ;particular year
s2:
	mov ax,[si]
	mov es:[bx],ax
	mov ax,0
	mov es:[bx+2],ax
	add bx,16
	add si,2
	loop s2  ;income
	mov cx,5
	mov si,30
	mov bx,10
s3:
	mov ax,[si]
	mov es:[bx],ax
	add bx,16
	add si,2
	loop s3    ;employee
	mov cx,5
	mov si,0    ;Number of bytes per line
s4:
	mov ax,es:[si+5]  ;income
	mov bl,es:[si+10]  ;Number of employees
	div bl
	mov es:[si+13],al  ;per capita income
	add si,16
	loop s4    ;average income
	mov ah, 4ch
	int 21h
code ends
end start

② After assembly and connection, load and debug the program in debug. Use u command, g command and d command flexibly and reasonably to display the beginning logic

The data information of the segment table, and the data information of the segment table after the structured data is stored, confirm to realize the subject requirements.

Before deposit

After deposit