Writing and debugging assembly source program for more than one logical segment in Experiment 2

Experiment Task 1
Tasks 1-1
task1_1.asm source

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

  


task1_1 Debug to end of line17, screenshot before line19

 

 

 


Question Answer
(1) In debug, before the end of line17 and line19, record this time: Register (DS) = _076A_u, Register (SS)
= _ 076B_u, Register (CS) = u 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-2h_u, The segment address of the stack is
__X-h__.


Tasks 1-2
Task task1_2.asm source

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

  


task1_2 View screenshots of register DS, CS, SS values before debugging to the end of line17 and before line19

 

 

 


Question Answer
(1) In debug, before the end of line17 and line19, record this time: Register (DS) = _076A_u, Register (SS)
= u 076B_u, Register (CS) = u 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 _ X-2h_u, The segment address of the stack is
__X-h__.


Tasks 1-3
Task task1_3.asm source

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

  


task1_3 View screenshots of register DS, CS, SS values before debugging to the end of line17 and before line19

 

 

 


Question Answer
(1) In debug, before the end of line17 and line19, record this time: Register (DS) = _076A_u, Register (SS)
= u 076C_, 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-4h_u, The segment address of the stack is
__X-2h__.


Tasks 1-4
Task task1_4.asm source

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

  


task1_4 View screenshots of register DS, CS, SS values before debugging to the end of line17 and line19

 

 

 


Question Answer
(1) Before the end of line9 and line11 in debug, record this time: Register (DS) = u 076E_u, Register (SS)=
_ 076C_u, Register (CS) = u 076A_u
(2) Assuming that the segment address of the code segment is X_u after loading the program, Then, the segment address of the data segment is u X+2h_u, Segment address of stack
Yes_u X+4h_u.


Tasks 1-5
Based on the practice and observation of the above four experimental tasks, summarize and answer:
(1) For a segment defined below, the amount of memory space actually allocated to that segment after loading is u (Data length / 16) bytes.
(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 be executed correctly. Combined with the conclusions obtained from practical observation, the reasons are analyzed and explained.

 

 

Experiment Task Two

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
    add bx, 2					
    loop s

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

Run screenshots:

 

 

 

 

 

Experiment Task Three

Completed assembly source code:

assume ds:data1, 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, data1					
    mov ds, ax
    mov bx, 0
    mov cx, 0ah						
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

Disassembly:

 

 

  Before adding:

 

 

 

 

When added:

 

 

 

 

Experiment Task Four

Completed assembly source code

assume cs:code, ss:stack

data1 segment
    dw 2, 0, 4, 9, 2, 0, 1, 9
data1 ends 

data2 segment
    dw 8 dup(0)
data2 ends

; Defines a stack segment
stack segment
    dw 8 dup(0)
stack ends

code segment
start:
    mov ax, data1
    mov ds, ax			
    mov sp, 9				
    mov bx, 0
    mov cx, 8				
s1: push ds:[bx]
    add bx, 2				
    loop s1
	
    mov ax, data2		
    mov ds, ax
    mov bx, 0
    mov cx, 8				
s2: pop ds:[bx]
    add bx, 2
    loop s2

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

Debug in debug, disassemble results:

 

 

  data2 corresponds to local memory space:

 

 

 

Experiment Task Five

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

Result of running code:

 

 

 

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

 

 

  line19 controls letter size

line4 controls the color of letters

 

Experimental Task Six

task6.asm source

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

    mov bx, 0       
    mov cx, 4       
s1: 
    mov si, cx      
    mov cx, 4      
    
s2: 
    mov al, es:[bx]     
    or al, 20h          
    mov es:[bx], al     
    inc bx             
    loop s2             
  
    mov cx, si     
    mov bx, 0       
    mov ax, es      
    inc ax         
    mov es, ax     

    loop s1        

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

Load, disassemble, debug screenshots in debug

 

 

  Screenshot of memory space corresponding to data segment:

 

 

 

Experimental Task Seven

task7.asm source

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 ah, 4ch
    int 21h
code ends
end start

Screenshot of table segment raw data information

 

 

  Screenshot of memory space corresponding to table segment

 

 

 

Information is structurally written to specified memory on demand

 

Posted by threaders on Mon, 08 Nov 2021 19:45:32 -0800