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

Experimental task 1

Task 1-1

Source code:

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__ X-2__, The segment address of stack is__ X-1__

 

Task 1-2

 

Source code:

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__ X-2__, The segment address of stack is__ X-1__.

 

Task 1-3

 

Source code:

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

 

Tasks 1-4

 

Source code:

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__ X+2__, The segment address of 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 16*ceil(N/16)

②     task1_4.asm can still be executed correctly, because the entry of the original program is described after end. If it is empty, the program will be executed from scratch, only Task1_ The beginning of 4 is the content of the code segment.

Experimental task 2

Source code:

assume cs:code

code segment
start:
    mov ax,0b800h
    mov ds,ax
    mov bx,0f00h
    mov cx,80

s:  mov [bx],0403h
    add bx,2
    loop s

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

 

 

Experimental task 3

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:
    mov ax,data1
    mov ds,ax
    mov ax,data2
    mov es,ax
    mov bx,0
    mov cx,10
s:  mov al,[bx]
    add es:[bx],al
    inc bx
    loop s
    mov ax,data3
    mov ds,ax
    mov bx,0
    mov cx,10
s0: mov al,es:[bx]
    mov [bx],al
    inc bx
    loop s0

mov ax,4c00h
int 21h
code ends
end start

  Initial state:

 

  After execution:

 

Experimental task 4

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

code segment
start:
    
    mov ax, data1
    mov ds, ax
    mov ax, data2
    mov ss, ax
    mov sp, 16
    mov bx, 0
    mov cx, 8
  s:push [bx]
    add bx, 2
    loop s

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

Before and after execution

 

 

Experimental task 5

Source code:

assume cs:code, ds:data
data segment
        db 'Nuist'
        db 5 dup(5)
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

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)

  line15 set the number of cycles to 5, that is, the number of NUIST characters. Lines 16 and 17 set the initial values of the data segment and the video memory address offset respectively. Lines 18 and 19 copy the contents of the data segment into register ax and convert all characters into uppercase. Line 20 sends the value in register ax to the video memory address space, The last five bytes of the data segment in lines 21 and 22 are respectively sent to the cells adjacent to the first five characters in the video memory address space to set the color of each character.

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

  The values here are used to set the color of the displayed characters

Experimental task 6

Program 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
    s0:
        mov al,ds:[bx+si]
        or al,00100000B
        mov ds:[bx+si],al
        inc si
   loop s0
   add bx,16
   mov cx,dx
   loop s
   mov ah, 4ch
   int 21h
code ends
end start

  Before and after program execution:

 

 

Experimental task 7

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 bx, 0
    mov si, 0
    mov cx, 5

 s0:mov ax, ds:[bx]
    mov es:[si], ax
    mov ax, ds:[bx+2]
    mov es:[si+2], ax
    add bx, 4
    add si,10h
    loop s0

    mov bx, 20  ;Skip 20 bytes of year
    mov si, 5
    mov cx, 5
 s1:mov ax, ds:[bx]
    mov es:[si], ax
    mov word ptr es:[si+2], 0   ;The high address part of the revenue field is set to 0
    add bx, 2
    add si, 10h
    loop s1

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

    mov si, 0
    mov cx, 5
 s3:mov ax, es:[si+5]   ;The lower 16 bits of the divisor are placed in ax in
    mov dx, es:[si+7]   ;16 bit high, placed in dx in
    div word ptr es:[si+10]
    mov es:[si+13], ax    ;Move quotient into position

    add si, 10h
    loop s3

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

 

 

 

 

 

 

 

Posted by rheroux on Mon, 08 Nov 2021 15:28:03 -0800