Experiment 2 Writing and Debugging Assembly Source Programs for Multiple Logical Segments

Posted by annihilate on Thu, 11 Nov 2021 18:01:28 +0100

1. Experimental Task 1

Tasks 1-1

task1_1.asm

assume ds:data, cs:code, ss:stack
data segment   db
16 dup(0) ; Reserve 16 byte cells with initial values of 0 data ends
stack segment   db
16 dup(0) ;Reserve 16 byte cells with initial values of 0 stack ends code segment start:   mov ax, data   mov ds, ax
  
mov ax, stack   mov ss, ax   mov sp, 16 ; Set top of stack
  mov ah, 4ch   int 21h code ends end start

(1) In debug, before the end of line17 and line19, record this time: Register (DS) = _076A_u, Register (SS) = u 076B_u, Register (CS) = _076C_u_

(2) Assuming that the segment address of the code segment is X after loading the program, the segment address of the data segment is u X-0002H_u, The segment address of the stack is u X-0001H_u.

Tasks 1-2

task1_2.asm

assume ds:data, cs:code, ss:stack
data segment   db
4 dup(0) ; Reserve 4 byte cells with initial values of 0 data ends
stack segment   db
8 dup(0) ; Reserve 8 byte units with initial values of 0 stack ends code segment start:   mov ax, data   mov ds, ax
  
mov ax, stack   mov ss, ax   mov sp, 8 ; Set top of stack

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

 

 

(1) In debug, before the end of line17 and line19, record this time: Register (DS) = _076A_u, Register (SS) = u 076B_u, Register (CS) = _076C_u_

(2) Assuming that the segment address of the code segment is X after loading the program, the segment address of the data segment is u X-0002H_u, The segment address of the stack is u X-0001H_u.

Tasks 1-3

task1_3.asm

assume ds:data, cs:code, ss:stack

data segment
    db 20 dup(0) ; Reserve 20 byte units with initial values of 0
data ends
stack segment
    db 20 dup(0) ; Reserve 20 byte units with initial values of 0
stack ends

code segment
start:
    mov ax, data
    mov ds, ax
    mov ax, stack
    mov ss, ax
    mov sp, 20 ; Set Initial Stack Top

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

 

 

(1) In debug, before the end of line17 and line19, record this time: Register (DS) = _076A_u, Register (SS) = u 076C_u, Register (CS) = _076E_u_

(2) Assuming that the segment address of the code segment is X after loading the program, the segment address of the data segment is u X-0004H_u, The segment address of the stack is u X-0002H_u.

Tasks 1-4

task1_4.asm

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

(1) In debug, before the end of line17 and line19, record this time: Register (DS) = _076C_u, Register (SS) = u 076E_u, Register (CS) = _076A_u_

(2) Assuming that the segment address of the code segment is X after loading the program, the segment address of the data segment is u X+0002H_u, The segment address of the stack is u X+0004H_u.

Tasks 1-5 summarize and answer based on the practice and observation of the four experimental tasks mentioned above:

(1) For a segment defined below, the amount of memory space actually allocated to that segment after loading is u N bytes u.

xxx segment
    db N dup(0)
xxx ends

(2) If the program task1_ 1.asm, task1_ 2.asm, task1_ 3.asm, task1_ 4. In asm, the pseudo-directive end start is changed to end, which program can still execute correctly? Combined with the conclusions obtained from practical observation, the reasons are analyzed and explained.

A: task1_4.asm, after the pseudo instruction end start is changed to end, the program executes from the beginning, only   task1_4.asm satisfaction

2. Experimentation Task 2 writes an assembly source program to fill successively 160 bytes of hexadecimal data 03 04 into memory unit b800:0f00 ~ b800:0f9f.

assume cs:code
code segment
    mov ax, 0b800h
    mov ds, ax
    
    mov bx, 0f00h
    mov ax, 0403h
    mov cx, 160
s:  mov [bx], ax
    add bx, 2
    loop s
    
    mov ah, 4ch
    int 21h
code ends
end

 

 

  3. Experimental Task 3

The code snippet for the 8086 assembly source program task3.asm is known below.

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

    mov cx,10
    mov bx,0
s1: mov al,es:[bx]
    add [bx],al
    inc bx
    loop s1

    mov ax,data2
    mov es,ax

    mov cx,10
    mov bx,0
s2: mov al,es:[bx]
    add [bx],al
    inc bx
    loop s2

    mov ah,41h
    int 21h

code ends
end start

date1

 

date2

 

 

 

 

 date3

 

 

  When added:

 

  4. Experimental Task 4

The code snippet for the 8086 assembly source program task4.asm is known below.

task4.asm

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 es,ax
    mov sp,16

    mov bx,0
    mov cx,8
s1: push [bx]
    add bx,2
    loop s1

    mov bx,0
    mov cx,8
s2: pop [bx]
    add bx,2
    loop s2

    mov bx,0
    mov cx,8
s3: mov ax,[bx]
    mov es:[bx],ax
    add bx,2
    loop s3

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

 

  5. Experimental Task 5

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

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

 

The function of line19 is to convert letters to uppercase and lowercase

The effect of line4 is to change the color of the display

6. Experimental Task 6

The code snippet for the 8086 assembly source program task6.asm is known below.

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

    mov cx,4
    mov bx,0
s:  mov dx,[bx]
    mov ax,dx
    add al,32
    mov [bx],ax
    add bx,16
    loop s

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

 

 

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 si,0
    mov di,0
    mov cx,5
s:
    mov ax,ds:[si]
    mov es:[di], ax
    mov ax,ds:[si+2]
    mov es:[di+2], ax
    mov ax,ds:[si+84]
    mov es:[di+5],ax
    mov dx,ds:[si+84+2]
    mov es:[di+7],dx
    push cx
    mov cx,ds:[84+84+bx]
    mov es:[di+0ah],cx
    div cx
    pop cx
    mov es:[di+0dh],ax
    add si,4
    add bx,2
    add di,16
loop s

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

table raw data:

  After running: