1. 实验任务1 此部分书写内容:
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, 汇编指令 loop s1 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明 是如何计算得到跳转后标号s1其后指令的偏移地址的。
Loop s1的机器码E2F2,位移量是f2(1111 0010),反码1111 0001,所以原码是1000 1110(-14)
从cpu的角度:loop指令修改ip指向000DH,而loop指令接下来一条指令的ip为001BH,则位移量为 0DH-1BH=13-27=-14
② line44,汇编指令 loop s2 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明 是如何计算得到跳转后标号s2其后指令的偏移地址的。
Loop s1的机器码E2F0,位移量是f2(1111 0000),反码1110 1111,所以原码是1001 0000(-16)
从cpu的角度:loop指令修改ip指向0029H,而loop指令接下来一条指令的ip为0039H,则位移量为 29H-39H=41-57=-16
③ 附上上述分析时,在debug中进行调试观察的反汇编截图
2. 实验任务2
程序task2.asm源码
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
给出分析、调试、验证后,寄存器(ax) = ? (bx) = ? (cx) = ? 附上调试结果界面截图
理论上:
mov word ptr ds:[0], offset s1 把s1的偏移地址赋给ds:[0],
call word ptr ds:[0] 把下一行s1的偏移地址放入栈,再转移到偏移地址为ds:[0]的地方(既s1: pop ax),最后把栈顶元素ds:[0]= offset s1赋给ax。
同理 Bx=ds:[2]= offset s2
pop cx 把栈底元素CS赋给cx
Debug调试:
Ax=0021,Bx=0026,Cx=076c。
恰好对应图一反汇编中的s1的偏移地址,s1的偏移地址,CS.
因此调试结果与理论分析结果一致。
实验三
assume cs:code
code segment
start: mov dl, '7'
call s
mov dl, '9'
call s
mov ax, 4c00h
int 21h
s: mov ax, 0b800h
mov es, ax
mov es:[0], dl
ret
code ends
end start
data segment
x db 99, 72, 85, 63, 89, 97, 55
len equ $- x
data ends
assume cs:code
code segment
start:
call s
call c
mov ax, 4c00h
int 21h
s: mov dl, 7
mov ax, 0b800h
mov es, ax
or dl, 30H
mov es:[0], dl
ret
c: mov dl,'8'
mov ax, 0b800h
mov es, ax
mov es:[0], dl
ret
code ends
end start
三
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 byte ptr ds:[10], 10
mov cx,len
s1:
mov ah, 0
mov al, ds:[si]
div byte ptr ds:[10]
call printNumber
call printSpace
inc si
loop s1
mov ah, 4ch
int 21h
printNumber:
mov bx,ax
or bl, 30h
or bh, 30h
mov ah,2
mov dl ,bl
int 21h
mov dl,bh
int 21h
ret
printSpace:
mov ah, 2
mov dl, ' '
int 21h
ret
code ends
end start
实验四
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 bh, 0 ;指定第一行
mov bl, 2 ;黑底绿字
call printStr
mov bh, 24 ;指定最后1行
mov bl, 4 ;黑底红字
call printStr
mov ah, 4ch
int 21h
printStr:
mov al,0ah ;每行160字节
mul bh ;与行号相乘获得行起始地址
add ax, 0b800h
mov es,ax
mov si,offset str
mov cx,len
mov di,si
s:
mov al,[si]
mov ah,bl ;颜色属性
mov es:[di],ax ;把要显示的str放进显存
inc si
add di,2
loop s
ret
code ends
end start
实验五
data segment
stu_no db '201983290065'
len = $ - stu_no
data ends
code segment
start:
mov ax, data
mov ds, ax
mov di, 0
call print
mov ah, 4ch
int 21h
print:
mov ax, 0b800h
mov es, ax
mov si, 1
mov al, 24
mov dl, 80
mul dl
mov cx, ax
printBlue:
mov al, 17h ;00010111
mov es:[si], al ;填充颜色
add si, 2
loop printBlue
sub si, 1
mov ax, 80
sub ax, len
mov dl, 2
div dl
mov dx, ax
mov cx, dx
call printheng
mov cx, len
printStu:
mov al, ds:[di]
mov ah, 17h
mov word ptr es:[si], ax
inc di
add si, 2
loop printStu
mov cx, dx
call printheng
ret
printheng:
mov al, '-'
mov ah, 17h
mov word ptr es:[si], ax
add si, 2
loop printheng
ret
code ends
end start