题目送这样的,R5存MSB的数,R4存LSB的数,求1691+5185-2178的值,并把结果放在R5:R4,我老师说我加法运算有问题,是哪里写错了啊?非常感谢,求助,已经改了n次了无果
MOV A, #19
MOV B, #89
MUL AB ;19*89=1691=069BH B:00000110 A:10011011
MOV R4,A ;A to R4
MOV R5,B ;B to R5 R5 holds the MSB of the number and R4 the LSB of the number.
CLR A
CLR C
MOV A, #41H ; 加上5185 = 1441H 低位R4先加
ADD A, R4 ; 是不是这个需要改成ADDC?
MOV R4, A ; copy result to R5
CLR C
CLR A
MOV A,#14H; higher part later
ADDC A, R5
MOV R5, A
CLR C
MOV A,R4
SUBB A,#82H; 减去2178=0882H
MOV R4,A;低位先减
MOV A,R5
SUBB A,#08H;高位再减
MOV R5,A
MOV M1,R4;save them into M1,M2
MOV M2,R5 ;the result is 89*19+5185-2178=4698 the hex of results is 125AH
.END
------解决方案--------------------------------------------------------
ADD A, R4 ; 是不是这个需要改成ADDC? 不需要
MOV R4, A ; copy result to R5
CLR C 去掉这条指令
CLR A
MOV A,#14H; higher part later
ADDC A, R5
SUBB A,#08H;高位再减 用subc
------解决方案--------------------------------------------------------
这个代码看着蛋疼,为何不用B呢
; 1691=069BH
MOV A, #9BH
MOV B, #06H
;+5185=1441H
CLR C
ADD A, #41H
ADDC B, #14H
;-2178=0882H
CLR C
SUB A,#82H
SUBC B,08H
MOV R4,A ;A to R4
MOV R5,B ;B to R5 R5 holds the MSB of the number and R4 the LSB of the number.