8051程序添加两个8位数字
英特尔8051是8位微控制器。它具有许多功能强大的指令和IO访问技术。在本节中,我们将看到使用8051的最简单的程序之一。
在这里,我们将使用此微控制器添加两个8位数字。寄存器A(累加器)在操作中用作一个操作数。在不同的寄存器组中有七个寄存器R0–R7。我们可以将它们中的任何一个用作第二个操作数。
我们在位置20H和21H取两个5FH和D8H,将它们相加后,结果将存储在位置30H和31H。
。
。
。
。
。
。
程序
MOVR0,#20H;set source address 20H to R0 MOVR1,#30H;set destination address 30H to R1 MOVA,@R0; take the value from source to register A MOVR5,A; Move the value from A to R5 MOVR4,#00H; Clear register R4 to store carry INCR0; Point to the next location MOVA,@R0; take the value from source to register A ADDA,R5;Add R5 with A and store to register A JNC SAVE INCR4; Increment R4 to get carry MOVB,R4;Get carry to register B MOV@R1,B; Store the carry first INCR1; Increase R1 to point to the next address SAVE: MOV@R1,A;Store the result HALT: SJMP HALT ;Stop the program
因此,通过添加5FH+D8H,结果将为137H。01H将存储在30H,37将存储在31H。
输出结果
。
。
。
。
。
。
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿