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

task1_1. Answer the screenshot question before the end of line17 and 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__.

task1_2. After debugging to the end of line17 and before line19, observe the screenshot of the values of registers DS, CS and SS and answer the question ①       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_.

task1_3. After debugging to the end of line17 and before line19, observe the screenshot of the values of registers DS, CS and SS and answer the question ①        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_.

task1_4. After debugging to the end of line17 and before line19, observe the screenshot of the values of registers DS, CS and SS and answer the question ①     In debug, execute until the end of line9 and before line11. Record this time: register (DS) =__ 076C__，   Register (SS) =_ 076E___，   Register (CS)=   _ 076A___

②     Suppose that after the program is loaded, the segment address of the code segment is x__, Then, the segment address of the data segment is_ X+2___，   The segment address of stack is_ X+4___.

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 + 1)*16byte_.

②     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. As shown in the figure above, task 1_ 1. An error will be reported after modification. Similarly, task1_2,task1_3.

Because end start indicates that the program starts after start:, if only end will be executed from the first line of the program, only task1_4 is the content of the code segment from the beginning, so there is only task1_4 can operate correctly.

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.

• Assembly source code

```assume cs:code
code segment
start:
mov ax,0b800h
mov ds,ax
mov bx,0f00h
mov cx,50h
mov ax,0403h
s:mov ds:[bx],ax
loop s

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

• Screenshot of operation results • 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 bx, 0
mov cx, 10

s:mov dx, 0
mov ax, data1
mov ds, ax
mov ax, data2
mov ds, ax

mov ax, data3
mov ds, ax
mov [bx], dx
inc bx
loop s

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

• Load, disassemble and debug screenshots in debug

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

And, after adding in turn, view the debug command and screenshot of the original value of memory space data corresponding to logical segments data1, data2 and data3   • 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
mov bx, 0
mov cx, 8
s:push [bx]
loop s

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

• 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.   ```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
loop s

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

• Screenshot of operation results Use the debug tool to debug the program, and use the g command to execute it once before the program returns (i.e. after ine25 and before line27)  What is the function of line19 in the source code?

0dfh is 1101111, the ASCII code difference between upper and lower case letters is 32, and 0dfh converts lower case letters to upper case letters.

What is the purpose of the byte data in the data segment line4 in the source code? Modify the character color.

```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 dx,cx
mov cx,4
mov si,0
p:
mov al,ds:[bx+si]
or al,00100000B
mov ds:[bx+si],al
inc si
loop p
mov cx,dx
loop s

mov ah, 4ch
int 21h
code ends
end start```
• Load, disassemble and debug screenshots 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. ```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 dx, 0
mov cx, 5
s1:
mov ax, ds:[bx]
mov es:[dx], ax
mov ax, ds:[bx+2]
mov es:[dx+2], ax
loop s1

mov bp, 5
mov cx, 5
s2:
mov ax, ds:[bx]
mov es:[dx], ax
loop s2

mov cx, 5
mov dx, 10
s3:
mov ax, ds:[bx]
mov es:[dx], ax
loop s3

mov cx, 5
mov dx, 5
s4:
mov ax, es:[dx]
mov bl, es:[dx+5]
div bl
mov es:[dx+8], al
loop s4

mov ah, 4ch
int 21h
code ends
end star```
• Debug screenshot

View screenshot of original data information of 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 whether the information is structurally written to the specified memory as required. Experiment summary:

The completion of this experiment needs to master the transfer of data between registers in the loop instruction and clarify the number of addresses skipped by each register.

Use the debug tool to debug the program, and use the g command to execute the screenshot before the program returns (i.e. after ine25 and before line27)

Posted on Sun, 07 Nov 2021 13:02:58 -0500 by EricS