Assembly help

Programming, for all ages and all languages.
Post Reply
fatalz

Assembly help

Post by fatalz »

Hi everyone ! i've been programming in c++ for years now and i always read how fast and memory efficient an assembly code is. So i've decided to give it a try and write a hello world code. here is part of it



MOV AH , 02h

MOV DL , 48h
INT 21h ; //PRINT H

MOV DL , 45h
INT 21h ;//PRINT E

MOV DL , 4ch
INT 21h ;//PRINT L

MOV DL , 4ch
INT 21h ;//PRINT L

MOV DL , 4fh
INT 21h ; //PRINT O



for some reason after it prints o, the programme enter in an infinite loop and keeps printing the "o" caractere. Does anyone know what the problem is ? and also is it worth learning assembly ? is it portable ?
Thanks in advance

PS: English is not my first language, so please excuse my syntax
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Assembly help

Post by Candy »

fatalz wrote: Hi everyone ! i've been programming in c++ for years now and i always read how fast and memory efficient an assembly code is. So i've decided to give it a try and write a hello world code. here is part of it



MOV AH , 02h

MOV DL , 48h
INT 21h ; //PRINT H

MOV DL , 45h
INT 21h ;//PRINT E

MOV DL , 4ch
INT 21h ;//PRINT L

MOV DL , 4ch
INT 21h ;//PRINT L

MOV DL , 4fh
INT 21h ; //PRINT O



for some reason after it prints o, the programme enter in an infinite loop and keeps printing the "o" caractere. Does anyone know what the problem is ? and also is it worth learning assembly ? is it portable ?
Thanks in advance

PS: English is not my first language, so please excuse my syntax
1. You're using DOS calls. Are you aware of that?

2. You don't terminate the program with DOS calls. Due to some coincidence, it ends up back at the o or somewhere near that. Terminate your program when you're done. Hint: int21/ah=4f iirc.
QuiTeVexat

Re:Assembly help

Post by QuiTeVexat »

My book says 0x4c, with return code in al. So something like:

Code: Select all

mov ax, 0x4c00
int 0x21
0x4c being the code for ah, and 0x00 the return value for al.

Happy assembling.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Assembly help

Post by Candy »

QuiTeVexat wrote: My book says 0x4c, with return code in al. So something like:

Code: Select all

mov ax, 0x4c00
int 0x21
0x4c being the code for ah, and 0x00 the return value for al.

Happy assembling.
Yup... it's 0x4C. I recall something like 0x4D being for exiting without return value?
fatalz

Re:Assembly help

Post by fatalz »

i see the problem now ! thanks a lot
Cjmovie

Re:Assembly help

Post by Cjmovie »

Is it always safe to assume DOS or BIOS won't mess up your registers during the call? Are they saved for you?

I had trouble with a real BIOS that didn't save register values.
JAAman

Re:Assembly help

Post by JAAman »

most of the time, any registers not marked as return values, will not be contaminated, but check the RBIL for more accurate, and machine specific details (there are a couple of exceptions)


[url=http://www.cs.cmu.edu/~ralf/files.html]
## ---- ----- RBIL[/url]
Post Reply