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
运行结果:
问题1
机器码为 E2F2
跳转的位移量为000dh-001bh=-14
在执行loop指令后cs ip指向目标指令076d:000d,指令没有告诉cpu转移的目的地址,而是告诉了cpu要转移的位移为向前14个字节,正好是到目标指令之间
其他指令长度的和。
问题2
机器码为E2F0
跳转的位移量为0029h-0039h=-16
在执行loop指令后cs ip指向目标指令076d:0029,指令没有告诉cpu转移的目的地址,而是告诉了cpu要转移的位移为向前16个字节,正好是到目标指令之间
其他指令长度的和。
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
执行第一个call指令时,s1指令的ip入栈,所以ax为s1指令的ip
执行第二个call指令是,s2指令的cs ip 依次入栈,所以bx为s2指令的ip,cx为s2指令的cs
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 di, 0 ;将数据段第一个数的地址保存下来 mov cx, 7 ;循环次数-1 s: mov dl, 10 mov ah, 0 mov al, [di] div dl call printNumber call printSpace inc di loop s mov ah, 4ch int 21h printNumber: mov bl, al ;将商转移到bl mov bh, ah ;将余数转移到bh or bl, 30h mov ah, 2 mov dl, bl int 21h or bh, 30h mov dl, bh int 21h ret printSpace: mov ah, 2 mov dl, ' ' ; 打印空格 int 21h ret code ends end start
assume ds:data,cs:code data segment str db 'try' len equ $ - str data ends code segment start: mov ax, data mov ds,ax mov cx,3 mov si,0 mov bl,ds:[si] mov di,0 ;设置输出在第一行 mov bh,02 s: mov bl,ds:[si] call printStr add di,2 inc si loop s mov si,0 mov di,0F00h ;屏幕最后一行 mov cx,3 s1: mov bl,[si] mov bh,04 call printStr add di,2 inc si loop s1 printStr: mov ax,0b800h mov es,ax mov es:[di],bx ret mov ax, 4c00h int 21h code ends end start
assume ds:data, cs:code data segment stu_no db '201983290104' len = $ - stu_no data ends code segment start: mov ax,data mov ds,ax mov ax,0b800h mov es,ax mov cx,2000 ;80×25 屏幕中所有字符 mov si,0 ;遍历整个屏幕 mov bh,17h mov bl,0 ;清除bl中杂乱信息 s: call print loop s mov cx,80 mov si,0f00h ;指向最后一行第一个字符 mov bl,'-' ;设置最后一行全为'-' s1: call print loop s1 mov cx,len mov si,0f44h s2: mov bl,[di] call print inc di loop s2 mov ah,4ch int 21h print: mov es:[si],bx add si,2 ret code ends end start