在8051微处理器中将两个8位数字相除的程序
在这里,我们将看到除法运算。使用此8051微控制器,此操作将被用于除以两个8位数字。寄存器A和B将用于此操作。没有其他寄存器可用于除法。除法的结果分为两个部分。商部分和余数部分。寄存器A将保留商数,寄存器B将保留余数。
我们在位置20H和21H取两个数字0EH和03H,相除后的结果将存储在位置30H和31H。
程序
MOV R0, #20H ; set source address 20H to R0 MOV R1, #30H ; set destination address 30H to R1 MOV A, @R0 ; take the first operand from source to register A INC R0 ; Point to the next location MOV B, @R0 ; take second operand from source to register B DIV AB ; Divide A by B MOV @R1, A ; Store Quotient to 30H INC R1 ; Increase R1 to point to the next location MOV @R1, B ; Store Remainder to 31H HALT: SJMP HALT ; Stop the program
8051提供了DIVAB指令。通过使用此指令,可以完成除法。在某些其他微处理器(如8085)中,没有DIV指令。在该微处理器中,我们需要使用重复的减法运算来获得除法结果。
当分母为00H时,溢出标志OV为1,否则除法为0。
输出结果