task1.asm源码:
1 assume cs:code, ds:data 2 3 data segment 4 x db 1, 9, 3 5 len1 equ $ - x 6 7 y dw 1, 9, 3 8 len2 equ $ - y 9 data ends 10 11 code segment 12 start: 13 mov ax, data 14 mov ds, ax 15 16 mov si, offset x 17 mov cx, len1 18 mov ah, 2 19 s1:mov dl, [si] 20 or dl, 30h 21 int 21h 22 23 mov dl, ' ' 24 int 21h 25 26 inc si 27 loop s1 28 29 mov ah, 2 30 mov dl, 0ah 31 int 21h 32 33 mov si, offset y 34 mov cx, len2/2 35 mov ah, 2 36 s2:mov dx, [si] 37 or dl, 30h 38 int 21h 39 40 mov dl, ' ' 41 int 21h 42 43 add si, 2 44 loop s2 45 46 mov ah, 4ch 47 int 21h 48 code ends 49 end start
从CPU的角度,说明 是如何计算得到跳转后标号s1其后指令的偏移地址的。
答:通过反汇编可以得到跳转的位移量为-14(反汇编得到为F2,F2为-14的补码),因为执行loop指令后,IP先加一再进行跳转。
答)从CPU的角度,说明 是如何计算得到跳转后标号s2其后指令的偏移地址的。
答:跳转的位移量为-16,原理与问题一相同。
task2.asm源码:
1 assume cs:code, ds:data 2 3 data segment 4 dw 200h, 0h, 230h, 0h 5 data ends 6 7 stack segment 8 db 16 dup(0) 9 stack ends 10 11 code segment 12 start: 13 mov ax, data 14 mov ds, ax 15 16 mov word ptr ds:[0], offset s1 17 mov word ptr ds:[2], offset s2 18 mov ds:[4], cs 19 20 mov ax, stack 21 mov ss, ax 22 mov sp, 16 23 24 call word ptr ds:[0] 25 s1: pop ax 26 27 call dword ptr ds:[2] 28 s2: pop bx 29 pop cx 30 31 mov ah, 4ch 32 int 21h 33 code ends 34 end start
答:(ax) = offset s1 (bx) = offset s2 (cx) = (cs)
与分析结果一致。
task3.asm源码:
1 assume cs:code, ds:data, ss:stack 2 3 data segment 4 x db 99, 72, 85, 63, 89, 97, 55 5 len equ $- x 6 db 0 7 data ends 8 9 stack segment 10 db 16 dup(0) 11 stack ends 12 13 code segment 14 start: 15 mov ax,data 16 mov ds,ax 17 18 mov ax,stack 19 mov ss,ax 20 mov sp,16 21 22 mov cx,len 23 mov bx,0 24 mov byte ptr ds:[len],10 25 26 s: mov ax,0 27 mov al,ds:[bx] 28 29 call printNumber 30 call printSpace 31 inc bx 32 loop s 33 34 mov ah,4ch 35 int 21h 36 37 printNumber: 38 push dx 39 div byte ptr ds:[len] 40 mov dx,ax 41 mov ah,2 42 add dl,30h 43 int 21h 44 45 mov dl,dh 46 mov ah,2 47 add dl,30h 48 int 21h 49 50 pop dx 51 ret 52 53 printSpace: 54 push dx 55 mov dl,' ' 56 mov ah,2 57 int 21h 58 59 pop dx 60 ret 61 62 code ends 63 end start
task4.asm源码:
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 si,0 mov cx,len mov bl,2 mov bh,0 call printStr mov si,0 mov cx,len mov bl,4 mov bh,24 call printStr mov ah,4ch int 21h printStr: mov ax,0b800h mov es,ax mov ax,0 mov al,bh mov dx,160 mul dx mov di,ax s: mov al,ds:[si] mov es:[di],al inc si inc di mov es:[di],bl inc di loop s ret code ends end start
task5.asm源码:
assume cs:code, ds:data data segment stu_no db '201983290132' len = $ - stu_no len1 = (80-len)/2 data ends code segment start: mov ax,data mov ds,ax mov bl,16 call printColor mov si,0 mov bl,23 mov bh,24 call printStr mov ah,4ch int 21h printColor: mov ax,0b800h mov es,ax mov ax,0 mov al,25 mov dx,0 mov dx,80 mul dx mov cx,ax mov al,' ' mov di,0 s: mov es:[di],al inc di mov es:[di],bl inc di loop s ret printStr: mov ax,0b800h mov es,ax mov ax,0 mov al,bh mov dx,160 mul dx mov di,ax mov al,'-' mov cx,len1 s1: mov es:[di],al inc di mov es:[di],bl inc di loop s1 mov cx,len s2: mov al,ds:[si] mov es:[di],al inc si inc di mov es:[di],bl inc di loop s2 mov al,'-' mov cx,len1 s3: mov es:[di],al inc di mov es:[di],bl inc di loop s3 ret code ends end start