汇编语言8之转移指令的原理

转移行为类型:

  • 无条件转换指令(如:jmp)
  • 条件转移指令
  • 循环指令(如:loop)
  • 过程
  • 中断

操作符offset

标号有段地址和偏移地址seg去段地址,offset去偏移地址

如果直接在寄存器中使用标号,获得的是ds和offset组合得到的数据值

功能:获取标号的偏移地址

将s处的内容复制到s0处

]

根据位移进行转移的jmp指令

短转移:jmp short 标号(转移到标号处执行指令)

这种格式的jmp指令实现的是段内短转移,对ip修改范围为-128-127

在一般的汇编指令中。汇编的idata(立即数)会出现在翻译后的指令中,但是对于jmp指令,机器码中没有转移的目的的地址,在汇编的时候会将绝对的标号地址替换成相对于当前ip指针的偏移地址

所以这条指令的功能就是:修改ip使得:(ip) = (ip)+8位的偏移(-128到127)

近转移:jmp near ptr 标号

和段转移一样,只不过相对ip的偏移编程了16位位移

远转移:jmp far ptr 段寄存器:偏移地址

转移地址在内存中的jmp指令

jmp word ptr ds:[]段内转移,位数只够改变ip的值

jmp dword ptr ds:[] 段间转移,高地址放的是目的的段地址,低地址放的是ip的地址

jcxz指令

有条件转移指令,所有的有条件转移指令都是短转移

如果cx==0,就会实现跳转

loop指令

(cx)=(cx)-1如果cx!=0跳转

分析下列程序

assume cs:codesg
codesg segment
		mov ax,4c00h
		int 21h
start: 
		mov ax,0
s:		nop
		nop
		
		mov di,offset s
		mov si,offset s2
		mov ax,cs:[si]
		mov cs:[di],ax
		
s0:		
		jmp short s

s1:		mov ax,0
		int 21h
		mov ax,0
		
s2:		jmp short s1
		nop
codesg ends
end start

这个程序最终会运行到mov ax,4c00h int 21h然后正常退出。

原因是jmp跳转的时候实际的机器码是相对当前pc+或者-多少字节,在运行到s处的jmp short s1的时候这条语句时,实际上机器码负数向上偏移-7个字节的形式进行的计算

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
myasm51,小型的51单片机汇编器源码。 基于Linux环境下编写的小型的51单片机汇编器,源码开放,采用lex和yacc两个扫描和分析工具创建,代码小巧,易于研读和分析。对汇编源程序2遍扫描完成汇编,可以生成列表文件,Intel的Hex格式的文件及.bin格式的映像文件,后两种文件可以直接下载到单片机上运行。源码程序包内包含若干示例汇编源程序(.asm),proteus的格式的数字种的仿真文件,用以测试编译结果,另有编译后的dos下的可执行文件myasm51.exe,可以在windows的命令窗口下运行。另外提供一个简明的用户手册以供参考。以下为程序包的README: What is Myasm51 =============== Myasm51 is an open source mini-assembler for the Intel MCS-51 family of microcontrollers or the compatible ones, distributed under the GPL license. By scanning the source file in two pass, Myasm51 translates a symbolic code in text file (assembly language source) into a machine executable object file. During the first pass, the assembler builds a symbol table from the symbols and labels used in the source file. In the second pass, the assembler maps the source file into machine code and generates the listing file through what it receives in the first pass. Myasm51 is an absolute assembler and only generates absolute object files in the plain binary file (with .bin extension) or the Intel Hex file (with .Hex extension) which can be read by any ROM programmer to burn the object code into the ROM space of microcontrollers. How to make =========== We assume that the UNIX utilities yacc and lex have been installed in you system, and following these steps to build Myasm51 by the super user 'root' in the Linux or the UNIX cloned system. # tar zxf myasm51-gk-20151208_121306.tar.gz # cd myasm51 # make # cp myasm51 /usr/local/bin done. How to use ========== [root@rh9 myasm51]# cd examples [root@rh9 examples]# myasm51 Myasm51 Assembler. Ver 0.01 Release 1, (20151231_165818) [email protected], Wed Sep 30 17:28:09 CST 2015 built: Dec 31 2015 - 17:04:44 Usage: myasm51 [-o] [-F] [-C] [-d] in.asm where -ob to output binary file 'in.bin' -oh to output hex file 'in.hx' (default format) -oH to output Intel Hex file 'in.Hex' -F to fill free bit with 0 or 1, (default 0) -C to turn on/off symbol case sensitive, (default on) -d to turn on/off the parser debug mode, (default off) [root@rh9 examples]# myasm51 dclk7seg2.asm Myasm51 Assembler. Ver 0.01 Release 1, (20151231_165818) [email protected], Wed Sep 30 17:28:09 CST 2015 built: Dec 31 2015 - 17:04:44 ;;;; Starting 1st Pass... ;;;; 1st Pass proceeded. ;;;; Starting 2nd Pass... ;;;; 2nd Pass proceeded. dclk7seg2.hx, 340(0x154) bytes assembled. [root@rh9 examples]# nl -ba dclk7seg2.hx |more ... 25 0000: | 25 .ORG 0 26 0000: 02 00 30 | 26 PowerON: LJMP Reset 27 | 27 28 0003: | 28 .ORG 0X0003 29 0003: 02 00 03 | 29 EXT_INT0_VECTOR: LJMP EXT_INT0_VECTOR 30 | 30 31 000B: | 31 .ORG 0X000B 32 000B: 02 00 7E | 32 TIMER_T0_VECTOR: LJMP TIMER_T0_INT 33 | 33 34 0013: | 34 .ORG 0X0013 ... [root@rh9 examples]# myasm51 -Cn pm51.asm Myasm51 Assembler. Ver 0.01 Release 1, (20151231_165818) [email protected], Wed Sep 30 17:28:09 CST 2015 built: Dec 31 2015 - 17:04:44 ;;;; Starting 1st Pass... ;;;; 1st Pass proceeded. ;;;; Starting 2nd Pass... ;;;; 2nd Pass proceeded. pm51.hx, 7760(0x1e50) bytes assembled. [root@rh9 examples]# nl -ba pm51.hx |more 1 | 1 ; PAULMON 8051 Debugger by Paul Stoffregen 2 | 2 ; Please distribute freely -- may not be sold, period. 3 | 3 4 | 4 ; .command +h58 ;set page height to 58 in listing file... 5 | 5 6 | 6 .equ start,0000h ;address for start of EPROM (0000h) 7 | 7 .equ program,2000h ;address for program loading location 8 | 8 9 0000: | 9 .ORG start 10 0000: 02 0B 08 | 10 rst: lJMP poweron 11 | 11 12 0003: | 12 .org start+3 ;ext int #0 13 0003: 02 20 03 | 13 LJMP program+3 14 000B: | 14 .org start+11 ;timer #0 15 000B: 02 20 0B | 15 LJMP program+11 16 0013: | 16 .org start+13h ;external interrupt routine #1 17 0013: 30 8A 03 | 17 jnb tcon.2,intr0 18 0016: 02 20 13 | 18 ljmp program+13h ;don't do ssrun if edge trigger'd 19 0019: 01 45 | 19 intr0: ajmp step ;but do ssrun if level trigger'd 20 001B: | 20 .org start+1bh ;timer #1 21 001B: 02 20 1B | 21 ljmp program+1bh 22 0023: | 22 .org start+23h ;serial port 23 0023: 02 20 23 | 23 ljmp program+23h 24 002B: | 24 .org start+2bh ;timer #2 (8052 only) 25 002B: 02 20 2B | 25 ljmp program+2bh ... [root@rh9 examples]# myasm51 -oH -Cn pm51.asm Myasm51 Assembler. Ver 0.01 Release 1, (20151231_165818) [email protected], Wed Sep 30 17:28:09 CST 2015 built: Dec 31 2015 - 17:04:44 ;;;; Starting 1st Pass... ;;;; 1st Pass proceeded. ;;;; Starting 2nd Pass... ;;;; 2nd Pass proceeded. pm51.Hex, 7760(0x1e50) bytes assembled. [root@rh9 examples]# nl -ba pm51.Hex |more 1 :03000000020B08E8 2 :03000300022003D5 3 :03000B0002200BC5 4 :03001300308A032D 5 :03001600022013B2 6 :0200190001459F 7 :03001B0002201BA5 8 :0300230002202395 9 :03002B0002202B85 10 :02003000A188A5 11 :02003200A180AB ... More about Myasm51 ================== For more information, see doc/myasm51_guide.pdf. Bug report ========== Please send email to [email protected] ========== Enjoy fun. [email protected] Thu Dec 31 17:43:48 CST 2015
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值