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

## Experiment task 1:

Task 1-1

task1_1.asm source code task1_1 screenshot before the end of line17 and line19

```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```

Screenshot:

Question answer ① in debug, execute until the end of line17 and before line19, and 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

Task task1_2.asm source code task1_2. After debugging to the end of line17 and before line19, observe the screenshot of register DS, CS and SS values

```; ex2.asm
assume cs:code
code segment
mov ax, 0b810h
mov ds, ax
mov bx, 0
mov ax, 101H
mov cx, 4
s:      mov [bx], ax
add bx, 2
add ax, 101H
loop s
mov ah, 4ch
int 21h
code ends
end　```

Answer to question ① in debug, execute until the end of line17 and before line19, and 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

Task task1_3.asm source code task1_3. Screenshot of the values of registers DS, CS and SS before the end of debugging to line17 and line19

```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```

Question answer ① in debug, execute until the end of line17 and before line19, and 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 task1_4.asm source code task1_4. After debugging to the end of line17 and before line19, observe the screenshot of register DS, CS and SS values

```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```

Question answer ① in debug, execute until the end of line9 and before line11, and 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___.

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

```xxx segment
db N dup(0)
xxx ends```

② If the pseudo instruction end start in the programs task1_1.asm, task1_2.asm, task1_3.asm and task1_4.asm is changed to end, which program can still be executed correctly. Combined with the conclusions obtained from practical observation, analyze and explain the reasons.

task1_4.asm can be executed. Because this file starts with a program segment and none of the others is, it cannot be executed normally.

## Experimental task 2

Assembly source code

```assume cs:code
3
4 code segment
5 start:
6     mov ax,0b800h
7     mov ds,ax
8     mov bx,0f00h
9     mov cx,80
10
11 s:  mov [bx],0403h
12     add bx,2
13     loop s
14
15     mov ah, 4ch
16     int 21h
17 code ends
18 end start```

Screenshot of operation results

Experimental task 3

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:
;hold asg Put your data in csg in
mov ax,data1    ;data1 Address on ax in
mov dx,data3    ;data3 Address on dx in

mov ds,ax    ;data1 Address on ds in
mov ss,dx    ;data3 Address on ss in
mov bx,0    ;Offset address
mov cx,8    ;Cycle 8 times

s1:        mov al,ds:[bx]    ;hold data1 Copy data to al in
mov ss:[bx],al    ;hold al Copy data to data3 in
inc bx            ;deviation++
loop s1

;hold data2 Data added to data3 in
mov ax,data2    ;data2 Address on ax in
mov ds,ax    ;data2 Address on ds in

mov bx,0    ;Control offset address
mov cx,8    ;Cycle 8 times

s2:        mov al,ds:[bx]    ;hold data2 Copy data to al in
mov ah,0h        ;High complement 0
mov dl,ss:[bx]    ;hold data3 Copy data to dl in
mov dh,0h        ;High complement 0
add ax,dx        ;hold dx Data plus ax Data exists ax in
mov ss:[bx],al    ;hold al Copy data to data3 in
inc bx
loop s2
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

## Experimental task 4

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
stack segment
db 16 dup(0)
stack ends
code segment
start:
mov ax, data1
mov ds, ax
mov ax, data2
mov ss, ax  ;
mov sp, 10h ;
mov bx, 0
mov cx, 8
s:  push [bx]
add bx, 2
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.

## Experimental task 5

task5.asm source code

```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```

Screenshot of operation results

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)

What is the function of line19 in the source code?

Change lowercase letters to uppercase letters

What is the purpose of the byte data in the data segment line4 in the source code?

Set color

Experimental task 6

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 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
add bx,16
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.

Experimental task 7

Screenshot of task7.asm source code debugging

```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

stack segment
db 16 dup(?)
stack ends

code segment
start:
mov ax, data
mov ds, ax
mov ax, table
mov es, ax
mov ax, stack
mov ss, ax

mov bx, 0
mov di, 0
mov cx, 5
s1: push cx
mov cx, 4
s2: mov al, [bx]
mov es:[di], al
inc bx
inc di
loop s2
add di, 12
pop cx
loop s1

mov di, 0
mov bx, 0
mov cx, 5
s3: mov ax, [20 + bx]
mov es:[di + 5], ax
mov dl, [30 + bx]
div dl
mov ah, 0
mov es:[di + 13], ax
mov ax, [30 + bx]
mov es:[di + 10], ax
add di, 10h
add bx, 2
loop s3

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

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

Posted by chyan on Thu, 11 Nov 2021 11:27:00 -0800