News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Printing Integers??

Started by paulfaz, October 26, 2006, 12:39:39 PM

Previous topic - Next topic

paulfaz

Hi,

Im trying to learn ASM, and ive come across a problem that is now driving me mad....

I started out by simply trying to retrieve the version of DOS and display it to the user, it all seems to work apart from the displaying it to the user bit..  Ive gone right down to bare bones now, ive removed all my "get dos version" stuff and all ive got is put a number in DL and print it to the screen.  It just dont work... Im sure theres something fundamental im doing wrong, any help is appreciated.

The code ive currently got is.....

   MOV   AH, 02h
   MOV   DL, 1
   INT   21h   

   MOV   AH,4ch      ; Exit Dos
   INT   21h


Now when i dont enclose the 1 in '1' i get a dodgy char printed to the screen, i presume im saying it is a string when enclosing it in '1', likewise IN21h Function 9 & 2 are both apparently "print STRING" functions so it makes sense that i cant print an integer????

Ive had a look through good old Ralf's INT list and i cant seem to find anything to print an Integer, am i going about this the wrong way??

As an example, how would i go about adding two numbers together and then printing the result of the addition on the console?

eek

I use ketman to teach me the basic asm stuff, it avoids me asking an awful lot of dumb questions.
http://www.btinternet.com/~btketman/tutpage.html
The asci character set has different codes for characters, 1 is a smiley for me.
mov dl,31
will give you number 1

ASM is hugely frustrating to learn, but truly fascinating once you start to put it together a bit.


Once you get past the total clueless dummy bit and start to put simple working snippets together for inputs and outputs you can make decisions on which direction you would like to go with your programming.

The biggest barrier for me was the huge amount of false starts I had over the years because I got sick of even the most simple stuff not compiling and I was spending hours of effort getting nowhere.

Ketman sorted that. Even as a thicko I gradually started to get the bigger picture.

It doesn't make other assemblers obsolete or anything like that because they have the potential of 32 bit nirvana, it just gives you a leg up onto the first rung of the ladder.

The amount of time and effort you will have to invest will still be considerable and there are lots of hair pulling days ahead.

Rockphorr

There is no "ready to use" function of int 21h to print integer.
You should write your function to do it.

know how:

1. Convert  one digit to one char by ADD:
mov AL,1
add  AL,"0" ; only for ten and less digits 0 ... 9

2. Get ordered digits by DIV
Any integer a2a1a0 is a0*10^0+a1*10^1+a2*10^2 where a0 a1 a2 are digits.

3. Create string of your integer by steps 1 & 2.

Strike while the iron is hot - Бей утюгом, пока он горячий

BytePtr

Its actually easy once you get started. Get some good ASM book.
This program is from head, coz its easy to do. :)

; gets current DOS version and writes it to screen

model small
stack 200h
codeseg
start:
mov ah, 30h ; get DOS version
int 21h ;

; print major version nr
add al, 30h ; convert to ASCII code
mov dl, al ;
mov ah, 02h ;
int 21h ; print it


mov dl, '.' ; print a "."
mov ah, 02h ;
int 21h ;

mov ah, 30h ; get DOS version
int 21h ;

; print minor version nr
add ah, 30h ; convert to ASCII code
mov dl, ah ;
mov ah, 02h ;
int 21h ; print it

xor ah, ah ; wait for keypress
int 16h

mov ah,04ch ; exit to DOS
int 21h ;

end start ; end of program


Tested under XP Pro (got version: 5.0), compiled with TASM 3.x
As an exercise for you: remove the 2 calls to DOS get version function (the mov ah,30h here) . Try it to make call it only once this function, but still showing correct version).

You will learn from it.
Any question? Just ask.

paulfaz

Hi Guys thanks for the information, i actually solved this last night before reading any of the above by viewing someones calc code and looking at how they printed it.  The problem is, i just dont grasp, WHY?? it is like it is..

Basically i added 30h, to AL to convert it??..... I dont understand why i needed to, why was it not stored already like it put it in...

When i do MOV AL, 1 does this not actually mean Move Interger Number 1 into AL, and rather means move 01h into AL??

Im really interested in learning all this, ive learnt other languages and i can do some of this asm stuff, im struggling with bits and bats likes...

The biggest issue for me is the inconsistancy in tutorials that are available, and the mass amount of info.  I prefer learning via practical methods, such as, right i wanna write a program to do x things, how do i acheive it, and learn on the way..  I tried reading through the Art Of Assembly and some others, and theres pages and pages of bits, nibbles and hex and mathamatical stuff that just makes a boring and "to much information at once" read...  The other issue is the inconsistancy in syntax due to different compilers, this is more true when looking at 32 bit ASM.

Anyway... Im enjoyin learning... I have another issue now though, but i will log a seperate call for it.

Thanks for all the answers above and the help.

Rockphorr

You must get ASCII code of digital symbol (like 0,1,2,3 ...).
This code you send to the video memory by call DOS fn or directly.
After your graphics adapter shows your symbol.
Strike while the iron is hot - Бей утюгом, пока он горячий

MichaelW

#6
Quote
Basically i added 30h, to AL to convert it??..... I dont understand why i needed to, why was it not stored already like it put it in...

When i do MOV AL, 1 does this not actually mean Move Interger Number 1 into AL, and rather means move 01h into AL??
When you do a MOV AL, 1 you are storing the number (value) 1 in AL (as binary bits, but the actual form in which the number is stored doesn't matter here). To display an ASCII character on the screen you specify the character by its character code. Within the ASCII character set the character codes for the decimal digits start at 30h, so the decimal numbers 0 to 9 can be converted to their character codes by adding 30h to the digit values. Larger decimal numbers convert to more than one digit, so the conversion is a little more involved, but not difficult if you understand how the decimal number system works.

eschew obfuscation