------------Restore content start------------
- The source code of the program task1.asm and the screenshot of its operation are given:
assume cs:code, ds:data data segment x db 1, 9, 3 len1 equ $ - x y dw 1, 9, 3 len2 equ $ - y data ends code segment start: mov ax, data mov ds, ax mov si, offset x mov cx, len1 mov ah, 2 s1:mov dl, [si] or dl, 30h int 21h mov dl, ' ' int 21h inc si loop s1 mov ah, 2 mov dl, 0ah int 21h mov si, offset y mov cx, len2/2 mov ah, 2 s2:mov dx, [si] or dl, 30h int 21h mov dl, ' ' int 21h add si, 2 loop s2 mov ah, 4ch int 21h code ends end start
- line27, when the assembly instruction loop s1 jumps, it jumps according to the displacement. Check the machine code through debug disassembly and analyze the jump displacement? (the displacement value is answered in decimal) from the perspective of the CPU, explain how to calculate the offset address of the instruction after the jump label s1
According to the machine code, the complement of the offset displacement is F2H, which is expressed as - 14 in decimal number, so the offset is 14; According to the space occupied by the opcode, the machine code occupies a total of 14 bytes from the last instruction after loop s1 to label s1.
-
line44. When the assembly instruction loop s2 jumps, it jumps according to the displacement. Check the machine through debug disassemblyWhat is the jump displacement of the code? (the displacement value is answered in decimal) from the perspective of CPU, it is explainedHow to calculate the offset address of the instruction after the jump label s2.
According to the results, the complement of the displacement is F0, which is converted to hexadecimal to - 16, so the offset is 16. Between the next instruction after loop s2 and label s2, the machine code occupies a total of 16 bytes.
- The program task2.asm source code is given
assume cs:code, ds:data data segment dw 200h, 0h, 230h, 0h data ends stack segment db 16 dup(0) stack ends code segment start: mov ax, data mov ds, ax mov word ptr ds:[0], offset s1 mov word ptr ds:[2], offset s2 mov ds:[4], cs mov ax, stack mov ss, ax mov sp, 16 call word ptr ds:[0] s1: pop ax call dword ptr ds:[2] s2: pop bx pop cx mov ah, 4ch int 21h code ends end start
-
After analysis, debugging and verification, register (ax) = 0021 (bx) = 0026 (cx) = 076C, attach the screenshot of the debugging result interface.
-
① According to the jump principle of call instruction, it is analyzed theoretically that the register (ax) before the program execution to exit (line31)=? register (bx) =? Register (cx) =?
A: theoretically, when using the call word instruction, the offset address (current ip) of his next instruction will be pushed into the stack. Therefore, when using the call word instruction for the first time, 0021 will enter the stack. The second call instruction is call dword. It is convenient to enter the cs: ip address into the stack. The first segment address in it will be saved with the offset address. Therefore, ax=0021, bx=0026, cx=076c
-
② Assemble and link the source program to get the executable program task2.exe. Use debug to debug, observe and verify debuggingAre the results consistent with the theoretical analysis
Answer: consistent
assume cs:code, ds:data data segment x db 99, 72, 85, 63, 89, 97, 55 len equ $- x data ends code segment start: mov ax, data mov ds, ax mov si, offset x mov cx, len mov bl,0ah s1: mov al, [si] mov ah,0;A 0 must be filled,The divisor must be 16 bits call printNumber inc si call printSpace loop s1 mov ah, 4ch int 21h printSpace proc mov ah, 2 mov dl, ' ' int 21h ret printSpace endp printNumber proc div bl;Divisor 8 bits mov dl,al;al Storage provider or dl,30h; mov dh,ah or dh,30h mov ah, 2 mov dl,dl int 21h mov dl,dh int 21h ret printNumber endp code ends end start
Screenshot of running test:
- The program source code task4.asm is given
assume cs:code, ds:data data segment str db 'try' len equ $ - str data ends code segment start: mov ax, data mov ds, ax mov ax, 0b800h ;B8000H~BFFFFH Space 32 in total KB The space is 80*25 Display buffer in color character mode mov es, ax mov si, offset str;Offset address - si mov cx, len; mov bl, 2h ;The color is green, mov bh, 0 ;The number of rows is row 0 call printStr mov si, offset str mov cx, len mov bl, 4h ;The color is red mov bh, 24 ;The number of lines is line 24 call printStr mov ax, 4c00h int 21h printStr: mov al, 160 ;Space occupied by each line of characters: Where characters are stored in high places ascll Code, with attributes stored in the low order mul bh ;8 Bit operands and AL Multiplication of registers; mov di, ax ;ax For the first bh Offset of row s: mov ah, ds:[si];character mov es:[di], ah mov es:[di+1], bl ;colour add di, 2 inc si loop s ret code ends end start
- Screenshot of running test
- The program source code task5.asm is given
assume ds:data, cs:code data segment str db '201983290280' len equ $ - str data ends code segment start: mov ax, data mov ds, ax mov ax, 0b800h mov es, ax mov cx, 4000 ;The number of bytes occupied by the content of each screen in the display buffer:80×25×2 = 4000Bytes mov di, 0 mov ah,17h ;White characters on blue background 00010111 s1: mov al, 0 mov es:[di], al mov es:[di+1], ah add di, 2 loop s1 ;At the beginning of the last line- mov di, 3840 ;Start on line 24 call printSign; ;Print student number mov di, 3908 ;3840+68 mov si, offset str mov cx, len mov ah, 17h s2: call printstr inc si add di, 2 loop s2 ;At the end of the last line- mov di, 3932 ;=3840-68 call printSign mov ax, 4c00h int 21h printstr: mov al, [si] mov es:[di], al mov es:[di+1], ah ret printSign: mov cx, 34 mov ah, 17h s :mov al, 2Dh ;- mov es:[di], al mov es:[di + 1], ah add di,2 loop s ret code ends end start
- Screenshot of running test