I'm a newbie and with assembly language programming, i've programmed in C and C++ already but assembly has been my intent from day one. Displaying strings and characters are easy and i've been able to display the sum of single digit numbers with the trick of subtracting 30h from the register with the stored sum and int 21/ah = 06. But now I want to take multi-digit input and display the sum. Now I don't know how to use dx:ax to store large numbers and the way i'm trying to store the input is to get each character and push it onto a stack then pop back each character and display them one by one but this seems time consuming can anyone please help me with this. I use int 21h/ah=01 for input and int 21h/ah =06 for output. I'm also using nasm assembler on a windows xp system and i've already read Assembly language Step by Step Programming by Jeff Duntemann from cover to cover but am still confused. Also any general help with displaying numbers mainly integers, floating point etc.
Posted on 2012-01-24 21:06:56 by Snake4eva
Add the numbers like normal then do radix change.

This is called change of radix
lets convert 30 from base 10 to base 2 (radix 10 to radix 2)
30/2 = 15 r0
15/2 = 07 r1
07/2 = 03 r1
03/2 = 01 r1
01/2 = 00 r1
So your answer is 11110

To do it to base 3 instead of 2 you do the same thing

33/3 = 11 r0
11/3 = 03 r2
03/3 = 01 r0
01/3 = 00 r1
The answer is 1020


The true beauty of this method is that EACH NUMBER is separate in the remainder... so push each one until you are done dividing and then pop it, add 30h, write it to the screen, and pop the next one :)
Posted on 2012-01-25 03:29:16 by watachiaieto
Thanks for your answer. I would also like to know if there aren't any interrupt that accept more multiple characters or digits like say how "scanf or cin" in C and C++ do. If there isn't then that means that DOS int 21h/ah =09 uses the push and pop techniques you just listed to print each character to the screen. Does anyone know how to use and construct a lookup table
Posted on 2012-01-25 07:56:26 by Snake4eva
Yeah, there are dos interrupts that will read and write multiple characters. The file-read and file-write interrupts would be most like what you'd use in a "grown up" OS. (I'm truly sad to say it, but that dos rebirth ain't happenin'!)

Lookup table...


section .data
digits db "0123456789ABCDEF"
section .text
  mov bx, digits ; "offset" for Masm folk
; get your number in al, 0 - 15
  xlatb
; now the corresponding character is in al
  stosb ; perhaps?
...


There are faster ways than xlatb, but that's probably easiest in 16-bit code.

Best,
Frank

Posted on 2012-02-01 01:37:08 by fbkotler