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

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

Experimental task 1

(1)task1_1.asm

1.DS=0770; SS=0771; CS=0772
2. The address of data section is X-2; stack section address is X-1;

Because the data segment and stack segment are allocated 16B units respectively, and the system allocates segment memory in 16B units, because the physical address = segment address × 16 + offset address, so there is a difference of 1H between the addresses of 16B segments
(2)task1_2.asm

Results in task1_1 same;
(3)task1_3.sam

1.DS=0770;SS=0772;CS-0774
2.data segment address X-4;stack segment address X-2;

At this time, the allocated address size is 20bit; Because the memory size is aligned with 2 bytes, 4 bytes are allocated.
(4)task1_4.asm

1.DS=0772;SS=0774;CS=0770;
2.data segment address X+2;stack section address X+4;
The change of address is related to the order in which memory is allocated

(5)task1_5.asm
1. Actually allocate [(N/16)] (rounded up) byte s of space
2.task4 can still run
Reason: you can see from the book that end start not only prompts where the program code ends, but also reminds where the program code starts. If start is removed, the system will take the beginning of the whole program as the beginning of the code by default. In experiments 1-1 to 1-3, the beginning of the program is the reservation of data segments and stack segments, not code segments, Therefore, the program can not run correctly, and experiment 1-4 changed the order of these paragraphs and put the code segment at the top, so it has no impact.

Experiment content 2

code:

Click to view the code
start:
    mov ax, 0b800h
    mov ds, ax
    mov bx, 0f00h
    mov cx, 80
    mov ax, 0403h
s:  mov ds:[bx], ax
    add bx, 2
    loop s

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

Experiment content 3

code:

Click to view the 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			;10 Group data
s: 	 mov ax, [bx]			; write in data1
	add ax, [bx+10h]		; hold data1+data2
	mov [bx+20h], ax		; Deposit data3
	inc bx
	loop s

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


Experiment content 4

Completion code:

Click to view the 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,10h
	mov bx,0
	mov cx,8
s:	push [bx]
	add bx,2
	loop s

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

Experiment content 5

Source code:

Click to view the 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

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.

Analysis results:
An and operation is performed in line 19, which is 00dfh, and the conversion to binary is 1101 1111. This binary performs an and operation with other binary numbers in the program. The result is that other positions remain unchanged, and the third bit becomes 0, which just conforms to the correspondence between small and medium letters in ASCII and uppercase. Therefore, the function of line 19 is to convert lowercase to uppercase.
Modify the value of 5 byte units in line4, reassemble, link, run and observe the results.

Modify the value of 5 byte units in line4, reassemble, link, run and observe the results.
DB 2,3,4,5,6 -- > changed to: db 5 dup(2)

Experiment 6

Completion code:

Click to view the code
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
s0:mov ax, cx
   mov cx, 4

s: or byte ptr [bx], 20h
   inc bx
   loop s

   add bx, 12
   mov cx, ax
   loop s0

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

result:

Experiment content 7

Completion code:

Click to view the code
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 si,0
    mov cx,5
s1: mov ax,ds:[bx]
    mov es:[si],ax
    add bx,2
    add si,2
    mov ax,ds:[bx]
    mov es:[si],ax
    add bx,2
    add si,14
    loop s1

    mov bx,20
    mov si,5
    mov cx,5
s2: mov ax,ds:[bx]
    mov es:[si],ax
    add si,2
    mov word ptr es:[si],0
    add bx,2
    add si,14
    loop s2

    mov bx,30
    mov cx,5
    mov si,10
 s3:mov ax,ds:[bx]
    mov es:[si],ax
    add bx,2
    add si,16
    loop s3

    mov bx,20
    mov di,30
    mov cx,5
    mov si,13
s4: mov ax,ds:[bx]
    mov dx,0
    div word ptr ds:[di]
    mov es:[si],ax
    add bx,2
    add di,2
    add si,16
    loop s4

    mov ah, 4ch
    int 21h
code ends
end start
Raw data memory distribution:


After structuring:

Posted by maxcell on Mon, 08 Nov 2021 21:36:58 -0800