Currently I am learning the assembly language. (I do not own any books so I am learning from the internet)
And I had a question about the stack.
Here is my script:
First I set bx and ax to 0. Then I put a 8 into ax and push it onto the stack. Then I put a 7 into bx and put it onto the stack. Now the stack has a total of 15 from ax and bx.
Then I get ax out of the stack. If I am not mistaken the stack now only contains the 7 from bx right?
tera4d wrote:First I set bx and ax to 0. Then I put a 8 into ax and push it onto the stack. Then I put a 7 into bx and put it onto the stack. Now the stack has a total of 15 from ax and bx.
Sort of. The stack contains two items - the 8 from register ax and 7 from register bx. They are not added together.
tera4d wrote:
Then I get ax out of the stack. If I am not mistaken the stack now only contains the 7 from bx right?
No. When you pop an item off the stack, you always get what you pushed most recently - the 7 from bx in your example.
@ru2aqare:
So the pop ax will retreive 7 because that is the last that is pushed to it ?
I think I get it =)
Thank you for your fast reply!
But all I have read about is programs being executed by a operating system so the os assigns a STACK to the program.
But how about declaring my own stack, How would I declare my own stack?
@thepowersgang:
Ohh I see!
About the BSS section forgive me for this question but I am still learning.
How can I use it? As I am using just a empty notepad file and save it as a .asm and compile with : nasm -f bin test.asm -o test.o
@thepowersgang:
Thank you ^^
Well about looking up I only found things involving linker scripts. But within the file I couldnt find something. I think that I am just looking at the wrong places haha.
I studied asm some more. And I also came across this great program! http://www.emu8086.com
And I tried to make a ASM script and it worked (perfectly in emu8060) but in bochs and virtual pc I only see a blinking cursor.
Here is my script:
(It sets up video mode 13h and then prints a string)
bits 16
org 7c00h
start: jmp prog
msg db "Hello, Joker!",0
prog:
mov ah, 00h ; set default video mode
mov al, 03h ; 80 collotions x 25 rows
int 10h ; Do it.
lea si, msg ; Move the message to print into SI
Call PrintString ; Print text to the screen.
jmp $ ; Halt PC
PrintString:
mov AH, 0Eh ; Request print.
p_loop:
lodsb ; Load byte from SI into AL.
cmp AL, 0 ; is ALs value 0?
jz p_done ; If so were done here.
int 10h ; use BIOS to Print charictar.
jmp p_loop ; Do it again.
p_done:
ret ; Return to call.
TIMES 510 - ($-$$) db 0 ; Add pading to make loader 512 bytes
DW 0xAA55 ; two extra bytes that make up a boot signature for the full 512.
note: not tested but it should work.
PS: emu8086 only emulates the old 8086 processor, Also do not right the image using emu8086
unless your going to run it on real hardware. other emulators don't seem to like the image
some reason
Last edited by Coty on Fri Jan 29, 2010 4:45 pm, edited 1 time in total.
@Coddy:
Thanks man. But I already wrote a routine like that one and it also worked flawlessly. But I wanted to go on and do something with a VGA mode (13h is the most simple one i've read) but it didnt work strangely. But as far as I know the complete x86 cpu line is backwards compatible right? http://www.ctyme.com/intr/int-10.htm < I have used this page as a reference.
> But as far as I know the complete x86 cpu line is backwards compatible right?
Yes, but what I am saying is for some res eon emu8086 does not create an FDD image that works with most emulators.
Oh, and that you'll be limited with your coding with it. But it is a fine choice for beginners, as long as you do not mind it being slow.
I assembled the code with : nasm -f bin boot.asm -o boot.bin
And then I added it to a floppy image with : winimage
Virtual pc / bochs both boot from it but then all I see is a blinking cursor.
I use emu8086 just to learn ASM (and as a great code editor). < also emu8086 uses FASM =D
But with the code I pasted above, well it has nothing to do with emu8086 it is just tested on it but it was written in notepad++ and assembled with NASM