-2

我如何汇编程序以找到两个数字中的最小值。

假设第一个数字位于内存地址:0x2001 第二个数字位于内存地址:0x2002

将较小的数字存储在累加器中

这是我尝试的:

LDA 0x2001
MOV B, A
LDA 0x2002
CMP B
JNC smaller
exit
smaller :
MOV A, B
exit : HLT

我的解决方案正确吗?

4

1 回答 1

1
XRA             ; clear the accumulator
MVI B, 30H      ; load a number to B Register
MVI C, 40H      ; load a number to C Register
MOV A, B        ; Move the content of B to A
CMP C           ; Compare value of C against A
JNC SMALL       ; Jump if smaller
**JMP END**         ; Halt program if not small
SMALL: MOV A, C ; save smaller num in accumulator
**END: HLT**
于 2012-12-20T18:19:19.347 回答