实验3 转移指令跳转原理及其简单应用编程
1.实验任务1
task1.asm源码:
assume cs:code, ds:data
data segment
x db 1, 9, 3
len1 equ $ - x ; 符号常量, $指下一个数据项的偏移地址,这个示例中,是3
y dw 1, 9, 3
len2 equ $ - y ; 符号常量, $指下一个数据项的偏移地址,这个示例中,是9
data ends
code segment
start:
mov ax, data
mov ds, ax
mov si, offset x ; 取符号x对应的偏移地址0 -> si
mov cx, len1 ; 从符号x开始的连续字节数据项个数 -> cx
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 ; 取符号y对应的偏移地址3 -> si
mov cx, len2/2 ; 从符号y开始的连续字数据项个数 -> cx
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:
跳转的位移量为001B-000D=000E=14
CPU首先到下一条指令地址001B,然后减去000D,得到E,向前移动E个单位。到000DH。
问题2:
跳转的位移量为0039-0029=0010=10
CPU首先移动到下一条指令地址0039,然后减去0029,得到0010,故向前移动10个单位,到0010H。
问题3:


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
问题1:
(ax)=offset s1
(bx)=offset s2
(cx)=cs=code
问题2:
验证ax寄存器,IP=0021 ->AX=0021

验证bx寄存器 ip=0026->bx=0026

验证cx寄存器cs=0076->cx=0076

3.实验任务3
task3.asm源码:
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 byte ptr ds:[len],10
mov cx,7
mov bx,0
s: mov al,ds:[bx]
mov ah,0
inc bx
call printNumber
call printSpace
loop s
mov ah,4ch
int 21h
printNumber:
div byte ptr ds:[len]
mov dx,ax
mov ah,2
or dl,30h
int 21h
mov ah,2
mov dl,dh
or dl,30h
int 21h
ret
printSpace:
mov dl,' '
mov ah,2
int 21h
ret
code ends
end start
测试截图:

4.实验任务4
task4.asm源码:
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 ax, 0b800h
mov es, ax
mov si, 0
mov di, 0
mov cx, len
mov bl, 02h
call printStr
mov si, 0
mov di, 160 * 24
mov cx, len
mov bl, 04h
call printStr
mov ax, 4c00h
int 21h
printStr:
s:
mov al, [si]
mov es:[di], al
inc di
mov es:[di], bl
inc di
inc si
loop s
ret
code ends
end start
测试截图:

测试截图:
5.实验任务5
task5.asm源码:
assume ds:data, cs:code
data segment
stu_no db '201983290061'
len = $ - stu_no
data ends
code segment
start:
mov ax,0b800h
mov es,ax
mov bp,1
mov cx,8000h
first:
mov byte ptr es:[bp],00011111B
add bp,2
loop first
mov ax,data
mov ds,ax;ds作数据段
mov ax,0050h;一行的长度
sub ax,len;减去学号的长度
mov bh,02h;除以二得到横线的长度
div bh
mov bl,al;商赋给bx,后面要用
mov bh,0
mov ax,0b800h;显存地址存给es
mov es,ax
mov bp,0F00h;首字母偏移量赋给bp
mov cx,bx
s:
mov byte ptr es:[bp],'-'
inc bp
inc bp
loop s;打印横杠
mov cx,len
mov di,0
s1:
mov al,ds:[di]
mov es:[bp],al
inc bp
inc bp
inc di
loop s1;打印学号
mov cx,bx
s2:
mov byte ptr es:[bp],'-'
inc bp
inc bp
loop s2;打印横杠
mov ax,4c00h
int 21h
code ends
end start
测试截图:


浙公网安备 33010602011771号