View Full Version : Assembler Language Subroutine
John_L
03-27-2008, 04:20 PM
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.
matsp
03-27-2008, 04:24 PM
If you have a modulo and divide operation, then something like this:
more:
load number
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
brewbuck
03-27-2008, 04:26 PM
[QUOTE=matsp;734741]If you have a modulo and divide operation, then something like this:
more:
load number
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.
John_L
03-27-2008, 04:31 PM
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?
matsp
03-27-2008, 04:33 PM
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
John_L
03-27-2008, 04:33 PM
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!
matsp
03-27-2008, 04:34 PM
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
John_L
03-27-2008, 05:35 PM
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?
brewbuck
03-27-2008, 05:49 PM
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 :)
John_L
03-27-2008, 06:10 PM
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!
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.