精通8051程序设计--田玉敏等译--指令集部分_第1页
精通8051程序设计--田玉敏等译--指令集部分_第2页
精通8051程序设计--田玉敏等译--指令集部分_第3页
精通8051程序设计--田玉敏等译--指令集部分_第4页
精通8051程序设计--田玉敏等译--指令集部分_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

飘风 精通 8051 程序设计 指令集部分 1 nop 指令 nop 指令仅仅占用一个字节 执行一个指令周期 尽管它等于 00h 但在调试 应用程序的时候 可以使用原来指令代替错误的指令 而不是擦出和重新编程器件 2 djnz 指令可用于计数循环 当计数值不为 0 时 它将计数值减 1 并转移 指令 djnz Rn Label 执行 Operand Operand 1 if Operand 0 PC Address 例 MCU 8051 mov R0 8 Loop 8x Loop djnz R0 Loop Skip Label jump if R0 0 mov R2 7 Loop djnz R2 Loop Decrement counter and jump if not zero 本例的代码循环 7 次之后才向下执行 3 条件转移指令 cjne cjne 进行一次比较操作并在结果等于 0 时转移 这些指令可以用来 测试用于转移指令的寄存器 累加器或其他的寄存器 是否已设置为 0 或某个值 cjne A Operand 指令 指令 cjne A 37 Label 执行 if Acc Operand PC Address 例 MCU 8051 cjne A 37 Label Jump to Label if Acc 37 Label cjne Register Data 指令 指令 cjne Reg Operand Label 执行 if Reg Operand PC Address 例 MCU 8051 cjne R2 37 Label Jump to Label if R2 37 Label 4 零转移 非零转移指令测试累加器的内容是否为零作为转移条件 这意味着 如果使用这 些指令 则在某一操作影响一个值之后 累加器的内容不能改变 指令 jnz Label 执行 JZ if Acc 0 PC Address JNZ if Acc 0 PC Address 例 MCU 8051 jz Label Jump to Label if Acc 0 Label 5 对于 8051 的间接寻址指令 用一个 i 来表示其索引寄存器 当前工作寄存器的 R0 或 R1 i 0 表示 R0 i 1 表示 R1 对于寄存器寻址 用 rrr 表示要访问工作寄存器中 的哪一个 6 典型的数据传送 或算术运算 指令的格式如下 ins Parm1 Parm2 Parm1 是操作结果的目标 也是操作的第 1 个可选参数 Parm2 通常是指令要读取的一个值 这意味着 mov A R0 其执行结果为 A R0 而 add A R0 其执行结果为 A A R0 在 8051 指令集的 A 表示累加器 位于地址 0E0h 的 ACC A 寄存器实际上是指令的一部 分 不能用其他寄存器来代替 如果指令中只有一个直接地址参数 ACC 必须隐式指定而 不是用 A 来指定 用 A 作参数会导致汇编代码时产生语法错误 7 对于 4 中寻址方式中的每一种 操作数都将被复制到累加器中 在 mov operand 中 A 指令的作用相同 累加器的内容将被复制到操作数中 作为寄存器寻址 或作为 8 位的直接 地址或间接地址寻址 在不使用累加器作为中间步骤 即 使用两条指令 mov A Operand2 mov Operand1 A 的 情况下 可以使用 mov Operand1 Operand2 传递数据 mov C bit 和 mov bit C 指令是在不影响寄存器中其他位的情况下 存取单个位非常有用 的指令 指令 mov A Operand A 执行 Operand A 例 MCU 8051 mov A 123 Put 123 into the R2 mov R2 A 8 指令 mov Direct Operand 执行 Destination Operand 例 MCU 8051 mov B 123 Put 123 into B 9 指令 mov Rn Oprnd 执行 目标操作数 原操作数 例 mov R2 123 Put 123 into R2 10 指令 mov C Bit 执行 C Bit 例 mov C P0 7 Move P0 7 to P2 6 mov P2 6 C 11 如果要查看位模式 则会注意有 8 位可供寻址 但在论述 8051 的体系结构时 曾指 出位于地址 020h 到 02fh 只需要 7 位用于寻址 共有 128 个通用位 当位地址的位 7 被 置位时 在这些和位指令中 将访问特殊功能寄存器空间中的位 这些位分别在 ACC PSW B P0 P1 P2 和 P3 寄存器中 指令 mov Bit C 执行 位 C 例 mov C P0 7 Move P0 7 to P2 6 mov P2 6 C 12 要获取 P1 的最低有效位 应使用指令 mov C P1 0 13 对 64K 数据空间的变址寻址可以利用 mov 和 movx 指令 使用工作组寄存器中的索引寄 存器 当前 8 个字节工作寄存器组中的 R0 或 R1 或者 DPTR 寄存器 指令 mov Ri Operand 执行 Ri 原操作数 例 mov R0 123 Put 123 into byte pointed to by R0 14 如其他地方所述 某些形式的 8051 有 256 个字节 只能使用索引寄存器访问的片内 RAM 使用 Ri 寄存器时 只能访问其前 256 个地址 当把 DPTR 用作索引寄存器时 则可 以访问整个 64K 数据空间 指令 mov A index 执行 A Index 例 mov DPTR Buffer Read from the start of the buffer mov A DPTR 15 指令 movx Index A 执行 Index A 例 mov DPTR Buffer Write to the start of the buffer mov DPTR A 16 指令 mov DPTR Const 执行 DPL Const Set DPTR to start of the buffer 17 指令 push direct 执行 SP SP 1 SP Addr 例 ntHandler Save PSW before executing interrupt push PSW interrupt handler pop PSW Restore PSW reti 18 指令 pop direct 执行 Addr SP SP SP 1 例 ntHandler Save PSW before executing interrupt push PSW pop PSW Restore PSW reti 19 指令 xch A Operand 将累加器的内容与指定寄存器的内容交换 执行 Temp ACC ACC Operand Operand Temp 20 指令 xchd A Ri 使用工作寄存器组中的索引寄存器来指定操作数寄存器的地址 并只交换两个寄存器的最低 4 位 21 指令 movc A A Index 执行 A A Index 例 mov DPTR Buffer Read from the third byte in the buffer located in 64Kmemory Space mov A 2 movc A A DPTR 当 DPTR 用作索引时 读数据存储器 使用 PC 时 读取控制存储器 22 指令 xch A Operand 执行 A Operand Operand A 例 xch A P1 Swap contents of A and Port1 23 指令 xchd A Operand 执行 A 3 0 Operand 3 0 Operand 3 0 A 3 0 例 xchd A TL0 Swap low 4 bits of A and timer0 low byte 24 在当前工作组 甚至前 256 个地址 中 计算两个 16 位数的和的程序段是 mov A VarB VarB VarB C add A C Add the low 8 bits first mov VarB A Store the low 8 bit result mov A VarB 1 Add the higher 8 bits addc A C 1 mov VarB 1 A 25 指令 add A Operand 执行 A A Operand C 8 V 8 AC 4 例 mov A 77 Add 100 to 77 add A 100 26 指令 addc A Operand 执行 A A Operand C C 8 V 8 AC 4 例 mov A 77 Add 100 to 77 as a 16 bit addition add A 100 clr A adc A 0 mov Temp 1 A Store result s high 8 Bits 27 指令 subb A Operand 执行 A A Operand C C 8 V 4 例 mov A 100 Subtract 77 from 100 add A 77 mov A VarB VarB VarB C clr C Clear carry before subtraction subb A C Subtract the low 8 bits mov VarB A mov A 1 Subtract the high 8 bits subb A C 1 mov VarB A 28 指令 inc Operand 执行 Operand Operand 1 例 inc R0 Increment R0 of the current bank inc Var Increment the lower 8 bits xch A Var cjne A 0 incSkip The lower 8 bits are not equal to zero inc Var 1 Increment the high 8 bits incSkip xch Var A Save the result of the lower 8 bit increment 29 指令 inc Operand 执行 Operand Operand 1 例 inc R0 Increment R0 of the current bank 30 指令 dec Operand 执行 Operand Operand 1 例 dec R0 Decrement the byte pointed to by R0 mov A Var Decrement the lower 8 bits clr C subb A 1 mov Var A jnc decSkip If carry set then decrement the upper 8 bits dec Var 1 decSkip 31 指令 inc DPTR 执行 DPTR 9 A Add two BCD numbers add A 0442h Note that the high 4 bits will be 1 da A 33 指令 mul AB 执行 B A A B 例 mov A 077h Find the product of two numbers mov B 042h mul AB 34 指令 div AB 执行 A A B B A B 例 mov A 077h Get the tens and ones of a number mov B 010h div AB mov A Number Store the number mov B 100 want to get the hundreds and remainders div AB mov Hundreds A Store the hundreds of the number mov A B Repeat for tens and ones mov B 10 div AB mov Tens A Store the tens of the number mov Ones B Store the ones of the number 35 指令 anl A Operand 执行 A A Add 100 to 77 to get 68 decimal anl A 100 36 指令 anl Register A 执行 Operand A Add the register with 77 anl Register A 37 指令 anl Register Const 执行 Operand Operand Clear everything but P0 0 38 指令 orl A Operand 执行 A A Operand 例 mov A 77 OR 100 to 77 to get 109 decimal orl A 100 39 指令 anl Register A 执行 Operand A Operand 例 mov A 77 OR the register with 77 orl Register A 40 指令 orl Register Const 执行 Operand Operand Constant 例 orl P0 1 Set P0 0 41 指令 xrl A Operand 执行 A A Operand 例 mov A 77 XOR 100 to 77 to get 41 decimal xrl A 100 42 指令 xrl Register A 执行 Operand A Operand 例 mov A 77 XORthe register with 77 xrl Register A 43 指令 xrl Register Const 执行 Operand Operand Constant 例 xrl P0 1 Toggle P0 0 44 指令 anl C Bit 执行 C Bit AND the bit with carry 45 指令 anl C Bit 执行 C C AND the inverted bit with carry 46 指令 orl C Bit 执行 C Bit C 例 orl C P1 4 OR the bit with carry 47 指令 orl C Bit 执行 C C Bit 例 orl C P1 4 OR the inverted bit with carry MACRO xorlbit Parm1 Parm2 XOR Parm1 and Parm2 and store result in Carry mov C Parm1 anl C Parm2 Do A Store the result mov C Parm2 Do A Combine the results ENDMACRO 48 指令 clr A 执行 A 0 例 clr A Clear the accumulator 49 指令 clr C 执行 C 0 例 clr C Clear the carry flag 49 指令 clr Bit 执行 Bit 0 例 clr P2 3 Clear the I 0 bit 50 指令 setb C 执行 C 1 例 setb C Set the carry flag 51 指令 setb Bit 执行 Bit 1 例 setb PSW RS0 Change the current register bank 52 指令 cpl A 执行 A 0FFh 例 cpl A Negate the value in the accumulator inc A 53 指令 cpl C 执行 C C 1 例 cpl C Complement the carry flag 54 指令 cpl Bit 执行 Bit Bit 1 例 cpl P1 4 Complement the I 0 bit 55 指令 rr A 执行 A 1 A Rotate accumulator by one bit 56 指令 rl A 执行 A 1 A Rotate accumulator by one bit 57 指令 rrc A 执行 A 1 C 7 C A Rotate accumulator by one bit through the carry flag 58 指令 rlc A 执行 A 1 C 1 C 7 例 rlc A Rotate accumulator by one bit through the carry flag 59 指令 swap A 执行 A A Swap the nybbles in the accumulator 60 指令 ljmpl Label 执行 PC Address 例 sjmp Label jump to Label Label 61 指令 acall Label 执行 Stack PC PC Address 例 lcall Label jump to subroutine Label Label 62 指令 ret 执行 PC Stack 例 lcall Label Jump to subroutine Label Label ret Return from subroutine mov DPTR Table DPTR Start of table mov A Index Get the index address clr C Multiply by 2 for the actual address rlc A jmp A DPTR Jump to the table Table ajmp Element0 Jump to the different elements ajmp Element1 63 指令 jmp A DPTR 执行 PC ACC DPTR 例 mov DPTR Table Start mov A Table Element jmp A DPTR jump to element in table 64 指令 jnb Bit Label 执行 JB if Bit 0 PC Ad

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论