ICode9

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

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

2021-12-02 21:03:48  阅读:108  来源: 互联网

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


1. 实验任务1

源码:

 1 assume cs:code, ds:data
 2 
 3 data segment
 4     x db 1, 9, 3
 5     len1 equ $ - x
 6 
 7     y dw 1, 9, 3
 8     len2 equ $ - y
 9 data ends
10 
11 code segment
12 start:
13     mov ax, data
14     mov ds, ax
15 
16     mov si, offset x
17     mov cx, len1
18     mov ah, 2
19  s1:mov dl, [si]
20     or dl, 30h
21     int 21h
22 
23     mov dl, ' '
24     int 21h
25 
26     inc si
27     loop s1
28 
29     mov ah, 2
30     mov dl, 0ah
31     int 21h
32 
33     mov si, offset y
34     mov cx, len2/2
35     mov ah, 2
36  s2:mov dx, [si]
37     or dl, 30h
38     int 21h
39 
40     mov dl, ' '
41     int 21h
42 
43     add si, 2
44     loop s2
45 
46     mov ah, 4ch
47     int 21h
48 code ends
49 end start

运行截图:

 问题①:

  line27, 汇编指令  loop s1  跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,其跳转的位移量是_-14__(位移量数值以十进制数值回答);

  从CPU的角度,说明 是如何计算得到跳转后标号s1其后指令的偏移地址的:

  答:查看 loop s1 的机器码为 E2F2 即对应指令偏移的地址为  F2  ,对应的原码,10进制表示为_-14__。

问题②:

  line44,汇编指令 loop s2 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,其跳转的位移量是_-16__(位移量数值以十进制数值回答);

  从CPU的角度,说明 是如何计算得到跳转后标号s2其后指令的偏移地址的:

  答:查看  loop s2 的机器码为  E2F0   即对应指令偏移的地址为  F0  ,对应的原码,10进制表示为_-16__。

问题③:

  上述分析时,在debug中进行调试观察的反汇编截图:

 

2. 实验任务2

源码:

 1 assume cs:code, ds:data
 2 
 3 data segment
 4     dw 200h, 0h, 230h, 0h
 5 data ends
 6 
 7 stack segment
 8     db 16 dup(0)
 9 stack ends
10 
11 code segment
12 start:  
13     mov ax, data
14     mov ds, ax
15 
16     mov word ptr ds:[0], offset s1
17     mov word ptr ds:[2], offset s2
18     mov ds:[4], cs
19 
20     mov ax, stack
21     mov ss, ax
22     mov sp, 16
23 
24     call word ptr ds:[0]
25 s1: pop ax
26 
27     call dword ptr ds:[2]
28 s2: pop bx
29     pop cx
30 
31     mov ah, 4ch
32     int 21h
33 code ends
34 end start

分析、调试、验证后,寄存器(ax) = _offset s1__(bx) = _offset s2__(cx) = _cs__。

反汇编验证截图:

 

3. 实验任务3

源码:

 1 assume cs:code, ds:data
 2 data segment
 3     x db 99, 72, 85, 63, 89, 97, 55
 4     len equ $ - x
 5 data ends
 6 code segment
 7 start:
 8     mov ax,data
 9     mov ds,ax
10     mov byte ptr ds:[len],10
11     mov cx,7
12     mov bx,0
13 s:  mov al,ds:[bx]
14     mov ah,0
15     inc bx
16     call printNumber
17     call printSpace
18     loop s
19     mov ah,4ch
20     int 21h
21 printNumber:
22     div byte ptr ds:[len]
23     mov dx,ax
24     mov ah,2
25     or dl,30h
26     int 21h
27     mov ah,2
28     mov dl,dh
29     or dl,30h
30     int 21h
31     ret
32 printSpace:
33     mov dl,' '
34     mov ah,2
35     int 21h
36     ret
37 code ends
38 end start

截图:

 

4. 实验任务4

源码:

 1 assume cs:code,ds:data,ss:stack
 2 data segment
 3     str db 'try'
 4     len equ $ - str
 5 data ends
 6 
 7 stack segment
 8     db 16 dup(0)
 9 stack ends
10 
11 code segment
12 start:
13     mov ax,data
14     mov ds,ax
15 
16     mov ax,stack
17     mov ss,ax
18     mov sp,16
19 
20     mov ax,0b800h
21     mov es,ax  ;显存地址空间
22 
23     mov si,offset str
24     mov cx,len
25     mov bl,2h    ;黑底绿字
26     mov bh,0
27     call printStr
28 
29     mov si,offset str
30     mov cx,len
31     mov bl,4h  ;黑底红字
32     mov bh,24
33     call printStr
34     mov ah,4ch
35     int 21h
36 
37 printStr: push bx
38     mov al,0a0h ;一行占160个字节
39     mul bh   ;160*bh->ax
40     mov bx,ax ;把偏移地址存在bx里
41     pop ax
42     mov ah,al;高位存放属性信息
43 
44 s:  mov al,[si] ;低位存放字符
45     mov es:[bx+si],ax
46     inc bx
47     inc si
48     loop s
49     ret
50 
51 code ends
52 end start

结果截图:

 

5. 实验任务5

源码:

 1 assume ds:data,cs:code
 2 data segment
 3     stu_no db '201983290264'
 4     len = $ - stu_no
 5 data ends
 6 
 7 code segment
 8 start:    mov ax,data
 9         mov ds,ax
10 
11         mov ax,0b800h
12         mov es,ax 
13 
14         mov si,1
15         mov cx,7D0h 
16 s:        mov byte ptr es:[si],17h
17         add si,2
18         loop s
19 
20         mov bx,0f00h
21         call prints
22         mov si,offset stu_no
23         mov cx,len
24 s2:        call printnum
25         loop s2
26         call prints
27         mov ah,4ch
28         int 21h
29 
30 prints:    mov cx,34
31 s3:        mov byte ptr es:[bx],'-'
32         add bx,2
33         loop s3
34         ret
35 
36 printnum:mov al,[si]
37         or al,30h   
38         mov byte ptr es:[bx],al
39         inc si
40         add bx,2
41         ret
42 code ends
43 end start

截图:

 

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

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

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

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

ICode9版权所有