实验3 转移指令跳转原理及其简单应用编程

实验任务一

1.给出程序task1.asm源码,及,运行截图

 

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

运行截图

 

 

2.回答问题①

① line27, 汇编指令 loop s1 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明 是如何计算得到跳转后标号s1其后指令的偏移地址的。

答:

位移量 14

mov dl, [si]   、 mov dl, ' '   共占4,

or dl, 30h    占3

int 21h 、 int 21h   共占4

inc si   占1

loop s1  占2

 

 

3.回答问题②

② line44,汇编指令 loop s2 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明 是如何计算得到跳转后标号s2其后指令的偏移地址的。

答:

位移量 16

mov dx, [si] 、 mov dl, ' '  共占4

int 21h 、 int 21h   共占4

or dl, 30h    占3

add si, 2     占3

loop s2      占2

 

 

实验任务二

1.给出程序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

 

2、给出分析、调试、验证后,寄存器(ax) = ? (bx) = ? (cx) = ? 附上调试结果界面截图

答:

(1)

ax=跳转s1之前的ip值  bx=跳转s2之前的ip值  cx=0跳转s2之前的cs值

因为call word ptr ds:[0]是短转移,跳转之前要将ip值压栈,然后在pop ax的时候出栈

 call dword ptr ds:[2]是长转移,压入cs 压入ip ,然后弹出的时候先弹出ip给了bx 然后弹出cs 给了cx

call word ptr ds:[0]之前运行到了076c:0021 压入0021,最后ax=0021预测一致

 call dword ptr ds:[2]之前运行到了076c:0026 压入076c:0026,最后bx=0026、cx=076c 预测一致

 

实验任务三

1、给出程序源码task3.asm

assume cs:code, ds:data
data segment
    x db 99, 72, 85, 63, 89, 97, 55
    len equ $- x
data ends

stack segment
db 16 dup(0)
stack ends

code segment
start:
    mov ax,data
    mov ds,ax

    mov ax,stack
    mov ss,ax
    mov sp,16

    mov cx,7
    mov si,0
    mov bl,10
s:
    mov ah,0
    mov al,[si]
    call printNumber
    inc si
    loop s

    mov ah, 4ch
    int 21h

printNumber:
    div bl      ;商在al 余数在ah 先输出十位,即商的位置,再输出个位
    mov dl,al
    mov bh,ah   ;dl存放十位,bh存放个位

    or dl,30h
    mov ah,2
    int 21h     ;输出十位

    mov dl,bh
    or dl,30h
    int 21h     ;输出个位

    call printSpace
    ret

printSpace:
    mov ah,2
    mov dl,' '
    int 21h
    ret
    
code ends
end start

2、运行测试截图

 

 

实验任务四

1、给出程序源码task4.asm

;一个字符用两个字节在存放
;低位存放它的ASCII码,高位存放它的属性(颜色等)

;7   6 5 4  3  2 1 0
;BL  R G B  I  R G B
;   ------     ----- 
;闪烁 背景 高亮 前景
;黑底绿字  :  0 000 0 010   为2
;黑底红字  :   0 000 0 100   为4 

;80*25彩色字符模式显示缓冲区,   每页25行80列
;偏移B8000-B809F对应第一行
;偏移B8F00-B8F9F对应第二十五行
;行偏移地址:x*00A0H

assume cs:code, ds:data

data segment
    str db 'try'
    len equ $ - str
data ends

stack segment
    db 16 dup(0)
stack ends

code segment 
start:
    mov ax,data
    mov ds,ax

    mov ax,stack
    mov ss,ax
    mov sp,16

    mov ax,0b800h
    mov es,ax

    ;在屏幕最上方以黑底绿字显示字符串
    mov si,0
    mov bh,0
    mov bl,2
    mov cx,3
    call getAddress
s:
    call printStr
    loop s

    ;在屏幕最下方以黑底红字显示字符串
    mov si,0
    mov bh,24
    mov bl,4
    mov cx,3
    call getAddress
s1:
    call printStr
    loop s1

    mov ah, 4ch
    int 21h

printStr:
    mov ah,bl
    mov al,[si]
    ;ax存放输出的信息

    mov es:[di],ax
    inc si
    add di,2
    ret

getAddress:
    mov al,0a0h
    mov ah,0
    mul bh
    ;结果在ax中
    mov di,ax
    ;输出显存地址为 es:[di]
    ret

code ends
end start

2、运行测试截图

 

实验任务五

1、给出程序源码task5.asm

;一个字符用两个字节在存放
;低位存放它的ASCII码,高位存放它的属性(颜色等)

;7   6 5 4  3  2 1 0
;BL  R G B  I  R G B
;   ------     ----- 
;闪烁 背景 高亮 前景
;蓝底白字  :  0 001 0 111   为17h  
;蓝底空格(前景为蓝色) 颜色属性 : 0 001 0 111 为17h  所以蓝底空格为1720h
;

;80*25彩色字符模式显示缓冲区,   每页25行80列
;偏移B8000-B809F对应第一行
;行偏移地址:x*00A0H

assume cs:code, ds:data

data segment
    stu_no db '201983290395'
    len = $ - stu_no
data ends

stack segment
    db 16 dup(0)
stack ends

code segment 
start:
    mov ax,data
    mov ds,ax

    mov ax,stack
    mov ss,ax
    mov sp,16

    mov ax,0b800h
    mov es,ax
    
    ;输出前24行蓝色背景
    mov cx,24   ;外循环24次,输出到最后一行前停止
    mov di,0
s1:
    push cx     ;cx压栈,进行内循环
    mov cx,80
    mov ax,1720h
    s2:
        mov es:[di],ax
        add di,2
        loop s2
    mov di,0
    pop cx
    mov ax,es
    add ax,0ah
    mov es,ax
    loop s1

    ;输出最后一行
    ;最后一行共80列,学号占中间12列
    ;所以前34列为 '-'  35至46列为学号  47至80为 '-'
    call print

    mov cx,12
    mov ah,17h
    mov bx,0
s3:
    mov al,[bx]
    mov es:[di],ax
    add di,2
    inc bx
    loop s3

    call print

    mov ah, 4ch
    int 21h

print:              ;输出'-'
    mov cx,34
    mov ah,17h
    mov al,'-'    
s4:
    mov es:[di],ax
    add di,2
    loop s4
    ret

code ends
end start

2、运行测试截图

 

 
 
posted @ 2021-11-26 21:18  『一定』  阅读(26)  评论(3编辑  收藏  举报