0

I have this program but i didn't understand it. Why is ral and dad used?

 1.  lxi h, 4050h 
 2.  mov e,m 
 3.  mvi d,00h 
 4.  inx h
 5.  mov a,m
 6.  mvi b,08h
 7.  lxi h,0000h 
 8.  mvlt: ral ; this line 
 9.  jnc add1 
 10. dad d 
 11. add1: dcr b ; this line
 12. jz store 
 13. dad h 
 14. jmp mvlt 
 15. store: shld 4052h ; this line
 16. rst 1
Kevin Brown-Silva
  • 40,873
  • 40
  • 203
  • 237
Kirsche
  • 13
  • 1

1 Answers1

0

The code multiplies the bytes at [4050h] and [4051h], and stores the 16 bit result into [4052h]. de = byte at [4050h] (d = 0, e = byte), a = byte at [4051h]. ral shifts a left 1 bit, shifting the most significant bit of a into carry. dad d adds de to hl. dad h shifts hl left 1 bit. shld stores the 16 bit product into [4052h].

rcgldr
  • 27,407
  • 3
  • 36
  • 61
  • How can shifting multiplier left help in multiplication? I didn't get the basic of shifting and multiplying. – Kirsche Mar 07 '15 at 03:22
  • @Kirsche - shifting the multiplier left into the carry bit is done to test the bits of the multiplier from most significant bit to least significant bit, one at a time. If a bit is set, the multiplicand is added to the product. After each step, the product is shifted left one bit. – rcgldr Mar 07 '15 at 04:20