ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2021-11-28 15:33:49  阅读:125  来源: 互联网

标签:code ah 编程 mov 指令 跳转 ax data ds


1.实验任务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

运行截图:

 问题1:

反汇编截图:

 跳转的位移量为-14。F2转换成原码后对应的十进制数值为-14,故位移量为-14。跳转过程如下:执行完LOOP 000D指令后,IP自动加2,变为001B,然后进行跳转,001B+(-E)= 000D,跳转至IP为000D处。

问题2:

反汇编截图:

 跳转的位移量为-16。F0转换为原码后对应的十进制数值为-16,故位移量为-16。跳转过程如下:执行完LOOP 0029指令后,IP自动加2,变为0039,然后进行跳转,0039+(-0010)=0029,跳转至IP为0029处。

问题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寄存器存放的是s1的偏移地址,bx寄存器存放的是s2的偏移地址,cx寄存器存放的是cs的段地址。因为执行call word ptr ds:[0]时,会将下一条指令s1:pop ax的IP值入栈,然后跳转执行s1:pop ax时,将栈顶的IP值赋给ax,这个IP值正好是s1的偏移地址。执行call dword ptr ds:[2]时,当前代码段的段地址cs和下一条指令的IP值相继入栈,各占据两个字节,然后跳转到执行s2段的代码,将栈顶的IP出栈赋给bx,再将段地址cs出栈赋给cx,而该IP值正好是s2的偏移地址。

(2)调试验证如下:

由该图可知,执行完call word ptr ds:[0]的IP值0021,在执行完s1:pop ax后被赋给了ax寄存器。

由图可知,执行完call dword ptr ds:[2]的CS=076C和IP=0026入栈,执行s2段后,bx = 0026,cx=076C

 

调试结果与分析结果一致。

 

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 cx,len
    mov si,0
s:
    mov al,[si]
    mov ah,0
    call printNumber
    call printSpace
    inc si
    loop s

    mov ah,4ch
    int 21h
printNumber:
    mov bl,10
    div bl
    
    mov bx,ax 

    mov dl,bl
    or dl,30h
    mov ah,2
    int 21h
 
    mov dl,bh
    or dl,30h
    mov ah,2
    int 21h
    ret
printSpace:
    mov dl,' '
    mov ah,2
    int 21h

    ret
code ends
end start

将data段内容逐个放入ax,除以bl的值,得到商和余数,商在al中,余数在ah中,转换成ASCII码分别输出。

运行测试截图:

 

 

4.实验任务4

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,offset str
     mov cx,len
     mov bl,00000010b
     mov bh,1
     call printStr

    mov si,offset str
    mov cx,len
    mov bl,00000100b
    mov bh,23
    call printStr

    mov ah,4ch
    int 21h
printStr:
    mov ax,0b800h
    mov es,ax

    mov ax,0
    mov al,bh
    mov dx,0a0h
    mul dx
    mov di,ax
s:
    mov ah,ds:[si]
    mov es:[di],ah
    mov es:[di+1],bl
    add di,2
    inc si
    loop s
    ret

code ends
end start

 

运行测试截图:

 

 

5.实验任务5

task5.asm源码:

assume ds:data, cs:code

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

code segment
start:
    mov ax,0b800h
    mov es,ax
    mov bp,1
    mov cx,8000h

 color:
    mov byte ptr es:[bp],00011111B
    add bp,2
    loop color

    mov ax,data
    mov ds,ax
    mov ax,0050h
    sub ax,len
    mov bh,02h
    div bh
    mov bl,al
    mov bh,0

    mov ax,0b800h
    mov es,ax
    mov bp,0F00h

    mov cx,bx
    s:
    mov byte ptr es:[bp],'-'
    add bp,2
    loop s

    mov cx,len
    mov di,0
    s1:
    mov al,ds:[di]
    mov es:[bp],al
    add bp,2
    inc di
    loop s1

    mov cx,bx
    s2:
    mov byte ptr es:[bp],'-'
    add bp,2
    loop  s2

    mov ax,4ch
    int 21h

code ends
end start

运行测试截图:

 

标签:code,ah,编程,mov,指令,跳转,ax,data,ds
来源: https://www.cnblogs.com/jy1122/p/15615294.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有