0

我试图了解这段汇编代码是如何进行 8 位乘法的。我确实知道每一行的作用,但我不明白它是如何产生整个乘法的。

你能解释一下它是如何产生乘法的吗?提前致谢

;=========================================================
;routine: mult_soft
;  function: 8-bit unsigned multiplier using
;           shift-and-add algorithm
;  input register:
;     s3: multiplicand
;     s4: multiplier
;  output register:
;     s5: upper byte of product
;     s6: lower byte of product
;  temp register: s2
;=========================================================

load s3, 2                          ;multiplicand
load s4, 2                          ;multiplier
mult_soft:
          load s5, 00               ;clear s5
          load s2, 08               ;initialize loop index
mult_loop:
          sr0  s4                  ;shift lsb to carry
          jump nc, shift_prod      ;lsb is 0
          add s5, s3               ;lsb is 1

shift_prod:     
          sra s5                   ;shift upper byte right,
                                   ;carry to MSB, LSB to carry
          sra s6                   ;shift lower byte right,
                                   ;lsb of s5 to MSB of s6
          sub s2, 01               ;dec loop index
          jump nz, mult_loop       ;repeat until i=0

          ret
4

0 回答 0