1. ## Assembler Language Subroutine

I'm trying to think of a way to make an OutDecimal subroutine in assembler language, where given a 16 bit integer, the routine prints a string which represents the number. Any idea's on how to start?

I'm thinking modulus arithmetic and possibly division in order to separate the 16 bit binary number into 4 4bit numbers. Just a thought though...

Any help would be great, thanks!

p.s. I'm using a basic simulator with limited instructions, so pseudo code or explanations would help more than code, thanks.

2. If you have a modulo and divide operation, then something like this:
Code:
```more:
modulo 10
store result in buffer
divide number by 10
if not zero goto more
printing:
print last entry of buffer
if not at start of buffer goto printing
return```
--
Mats

3. [QUOTE=matsp;734741]If you have a modulo and divide operation, then something like this:
Code:
```more:
modulo 10
store result in buffer
divide number by 10
if not zero goto more
printing:
print last entry of buffer
if not at start of buffer goto printing
return```
The printing part can also be implemented by pushing each digit onto the stack, then, once finished, popping them off and printing them in the order they pop. Saves you from having to make a buffer somewhere.

4. I wrote a divide subroutine, i'll have to look into writing one for modulous. That makes sense though, after dividing the values after the decimal points obviously "dissapear". Know anywhere to get good info for the modulo operation? Or a better way to achieve the operation?

5. Yes, the I used push to do a shortest possible print a number for PDP-11. Just make sure you push a marker (such as 0 or -1) to indicate the end of the number).

--
Mats

6. nevermind, stupid question. I forgot modulo was just the remainder in a division...So I just modify my routine to record the remainder. Awesome, thanks for the help guys!

7. Originally Posted by John_L
I wrote a divide subroutine, i'll have to look into writing one for modulous. That makes sense though, after dividing the values after the decimal points obviously "dissapear". Know anywhere to get good info for the modulo operation? Or a better way to achieve the operation?
If you do integer division, the modulo should come out as "remainder" - so you should be able to get it "for free" from your division function - when you can't divide any further, the left-over is your "Modulo".

--
Mats

8. I got it pretty much working, just not 100&#37; sure how to print the buffer values. Say I have the number 125, my buffer will contain 1, 2, 5 as entries let's say buffer[0], buffer[1], buffer[2]. I can easily load each buffer value into a register, but not sure how to print it. Can I just use the Ascii Table chart and tack on the value 48 and print?

9. Originally Posted by John_L
I got it pretty much working, just not 100% sure how to print the buffer values. Say I have the number 125, my buffer will contain 1, 2, 5 as entries let's say buffer[0], buffer[1], buffer[2]. I can easily load each buffer value into a register, but not sure how to print it. Can I just use the Ascii Table chart and tack on the value 48 and print?
Exactly

10. nice, it all came together. Couple bugs but other than that it's pretty much complete. Thanks for the help! Probably be back on here later cause I still got a couple of more mini programs to go. Gotta love learning assembler!