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

  1, Experimental task 1

Task 1-1

assume ds:data, cs:code, ss:stack
data segment
db 16 dup(0) ; 16 byte units are reserved, and the initial values are 0
data ends
stack segment
db 16 dup(0) ;16 byte units are reserved, and the initial values are 0
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov sp, 16 ; Set stack top
mov ah, 4ch
int 21h
code ends
end start

① 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-2 and the segment address of the stack is X-1.

 

 

Task 1-2

assume ds:data, cs:code, ss:stack
data segment
db 4 dup(0) ; Four byte units are reserved, and the initial value is 0
data ends
stack segment
db 8 dup(0) ; 8 byte units are reserved, and the initial values are 0
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov sp, 8 ; Set stack top
mov ah, 4ch
int 21h
code ends
end start

① 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-2 and the segment address of the stack is X-1.

 

 

Task 1-3

assume ds:data, cs:code, ss:stack
data segment
db 20 dup(0) ; 20 byte units are reserved, and the initial values are 0
data ends
stack segment
db 20 dup(0) ; 20 byte units are reserved, and the initial values are 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

 

  ① 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 code segment is X after the program is loaded, the segment address of data segment is X-4 and the segment address of stack is X-2.

 

Tasks 1-4

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

 

  ① In debug, execute until the end of line9 and before line11. Record this time: register (DS) = 076C, register (SS) = 076E, register (CS) = 076A

② 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+2 and the segment address of the stack is X+4.

 

Tasks 1-5

① For the segment defined below, after the program is loaded, the actual memory space allocated to the segment is (N+15)/16)*16.

analysis:

N can be divided by 16 (N/16)*16=N

N cannot be divided by 16 (N/16+1)*16=N+16

Because the allocated space after the program is loaded is one unit of 16 bytes

xxx segment
db N dup(0)
xxx ends

② 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.

A: the fourth instruction can be executed correctly

Analysis: if the entrance position is not specified, the program will be executed from the allocated space, and only the beginning of Article 4 is the instruction code.

 

 

2, Experimental task 2

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.

assume cs:code
code segment
    mov ax,0b800h
    mov bx,0f00h
    mov cx,160
    
s:  mov ds,ax
    mov [bx],0304h
    
    inc bx
    loop s
    
    mov ax,4c00h
    int 21h
code ends
end

 

 

3, Experimental task 3

① The programming adds the data of logical segment data1 and logical segment data2 in turn, and the results are saved in logical segment data3.

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,data1
    mov ds,ax           ;ds point data1
    mov ax,data2
    mov es,ax           ;es point data2
    mov bx,0
    mov cx,10
    
s:    mov ax,[bx]
    add es:[bx],ax       ;data1+data2 Delivered data2(es)
    inc bx
    loop s
    
    mov ax,data3
    mov ds,ax            ;ds point data3
    mov bx,0
    mov cx,10
    
s0: mov ax,es:[bx]        ;take es Values in(data1 and data2 Addition result of)Assign to data3 in
    mov [bx],ax
    inc bx
    loop s0
    
    mov ah, 4ch
    int 21h
code ends
end start

  ② Load, disassemble and debug in debug. Before and after the data items are added in turn, check the memory space corresponding to the three logical segments data1, data2 and data3 respectively. After adding them one by one, ensure that the results exist in the logical segment data3.

  data1, data2 before addition

  data3 before addition

  The added data1 has been overwritten

Added data2

  Add data3

 

 

4, Experimental task 4

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            ;ds point data1
    mov bx,0            ;ds:bx point data1 First unit of
    
    mov ax,data2        ;ds point data2
    mov ss,ax            ;Stack pointing data2
    mov sp,16            ;Set stack top pointing data2:16
    mov cx,8
    
s:    push [bx]
    add bx,2
    loop s
    
    mov ah, 4ch
    int 21h
code ends
end start

  Confirm to realize the subject requirements

 

5, Experimental task 5

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

 

 

What is the function of line19 in the source code?

  Change letters from lowercase to uppercase

 

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

Modify the value of 5 byte units in line4, reassemble, link, run and observe the results.

db 2,3,4,5,6
--> Change to:
db 5 dup(2) 

  The purpose is to control the font color

 

 

6, Experimental task 6

assume cs:code, ds:data

data segment
    db 'Pink Floyd      ' ; 16 byte
    db 'JOAN Baez       ' ; 16 byte
    db 'NEIL Young      ' ; 16 byte
    db 'Joan Lennon     ' ; 16 byte
data ends

code segment
start:
    mov ax,data
    mov ds,ax           ;set up ds point data paragraph
    mov bx,0            ;set up(bx)=0,ds:bx point'Pink Floyd'First letter of
    mov cx,4            ;Set the number of cycles 4 because there are 4 strings
    
s:    mov al,[bx]       ;take ASCII Code from ds:bx Take it out of the unit pointed to
    or al,00100000B     ;take al Medium ASCII The position of the code becomes lowercase
    mov [bx],al
    add bx,16           ;Because each string has 16 bytes
    loop s
    
    mov ah, 4ch
    int 21h
code ends
end start

Code basis: the ASCII code value of lowercase letters is 20H larger than that of uppercase letters

 

 

 

 

7, Experimental task 7

assume cs:code, ds:data, es:table

data segment
    db '1975', '1976', '1977', '1978', '1979' ;character string,1 Bytes
    dw  16, 22, 382, 1356, 2390               ;2 Bytes
    dw  3, 7, 9, 13, 28                       ;word Type data, 2 bytes
data ends

table segment
    db 5 dup( 16 dup(' ') )                   ;Table 5 rows, 16 bytes per row
table ends

code segment
start:
    mov ax,data
    mov ds,ax                                  ;ds point data
    mov ax,table
    mov es,ax                                  ;es point table
    
    mov si,0                                   ;byte
    mov bp,0                                   ;Number of rows
    mov cx,5                                   ;Number of cycles - number of rows
    
s0:                                            ;particular year,with'1975'take as an example
    mov ax,[si]
    mov es:[bp],ax
    add si,2                                   ;The first 2 bytes of the year,'19'
    mov ax,[si]
    mov es:[bp+2],ax
    add si,2                                   ;Last 2 bytes of year,'75'
    add bp,10h                                 ;Next row of table
    loop s0
    
    mov cx,5
    mov bp,0
    mov si,0

s1:                                       ;Revenue, starting from the fifth byte
    mov ax,[si+20]
    mov es:[bp+5],ax              
    mov ax,0000h
    mov es:[bp+7],ax              
    add si,2                
    add bp,10h
    loop s1
    
    mov cx,5
    mov bp,0
    mov si,0
    
s2:                                       ;Number of employees
    mov ax,[si+30]
    mov es:[bp+10],ax
    add si,2
    add bp,10h
    loop s2
    
    mov cx,5
    mov bp,0
    
s3:                                       ;per capita income
    mov ax,es:[bp+5]                      ;income
    mov bl,es:[bp+10]            
    div bl                                ;income/employee
    mov es:[bp+13],al
    add bp,10h
    loop s3
    
    
    mov ah, 4ch
    int 21h
code ends
end start

 

 

  table raw data

  debug runs until the end of the program

  Confirm writing table

 

Posted on Sat, 06 Nov 2021 02:52:02 -0400 by patrickmvi