Xavier
Xavier

Reputation: 323

How do I go about dividing in the LC-3?

Can some one please explain to me how to divide in the lc3. I'm really not understanding how to do it. For example, if i have the int 250 stored in a random memory location and it shows up as x0102 how do i do divide that to be able to break it apart so that 250 turns into 2, 5, 0?

Upvotes: 1

Views: 4752

Answers (1)

aqua
aqua

Reputation: 647

Unfortunately, LC3 does not have a divide instruction, so you'll have to fake it using repeated subtraction. So:

Number = 250
Divisor = 100
Result = 0
While number > divisor
  number = number - divisor
  result = result + 1

Now:

dividend = result
remainder = number

This can be repeated with the divisor decreasing in each iteration, which I'll leave as an exercise for the reader.

Upvotes: 1

Related Questions