Jump to content
  • Advertisement
Sign in to follow this  
andrew1123

What's wrong with this NASM code...

This topic is 4093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

...I'm new to NASM (and ASM for that matter) When I have STRING as "HELLO", it displays "HELLO". When I have STRING as "Hello", it displays "llo". BITS 16 ORG 07C00h MAIN: STRING DB "Hello",0 MOV SI,STRING CALL PR_STRING MOV AH,00h INT 16h INT 20h PR_STRING: LODSB OR AL,AL JZ RETURN MOV AH,0Eh INT 10h JMP PR_STRING RETURN: RET TIMES 510 - ($-$$) DB 0 DW 0AA55h Can anyone help me find the problem with the code? Thanks. [Edited by - andrew1123 on May 2, 2007 10:03:00 PM]

Share this post


Link to post
Share on other sites
Advertisement
i put MAIN before the rest, so I don't need to jump. But I'm gonna try putting the rest before MAIN and adding JMP MAIN. And yes, I'm trying out my first boot-loader.


Nope, when I add JMP, for some reason, it displays some weird 8 looking ascii symbol. I can't use call either. Maybe if I add STRING before JMP...

That doesn't work, either.

Share this post


Link to post
Share on other sites
(Im surprised your code didnt triple fault)

Either add "jmp MAIN" before your data, or move your data at the END
of the program ie:

BITS 16
ORG 07C00h

MAIN:
MOV SI,STRING
CALL PR_STRING
MOV AH,00h
INT 16h
INT 20h

PR_STRING:
LODSB
MOV AH,0Eh
OR AL,AL
JZ RETRN
INT 10h
JMP PR_STRING

RETRN:
RET

STRING DB "Hello",0

TIMES 510 - ($-$$) DB 0
DW 0AA55h

Everything else looks fine, besides your RET instruction (Where will it return to?)

Because the bootloader is pure binary, execution starts from the first line
of your file--whether its data or not. This is why you would need to "jump
over your data"


Share this post


Link to post
Share on other sites
Quote:
Original post by Crypter
(Im surprised your code didnt triple fault)

Either add "jmp MAIN" before your data, or move your data at the END
of the program ie:

BITS 16
ORG 07C00h

MAIN:
MOV SI,STRING
CALL PR_STRING
MOV AH,00h
INT 16h
INT 20h

PR_STRING:
LODSB
MOV AH,0Eh
OR AL,AL
JZ RETRN
INT 10h
JMP PR_STRING

RETRN:
RET

STRING DB "Hello",0

TIMES 510 - ($-$$) DB 0
DW 0AA55h

Everything else looks fine, besides your RET instruction (Where will it return to?)


It returns to after CALL PR_STRING

BTW, moving the DATA didn't do anything. It now displays nothing. And I tried using JMP MAIN, but that screwed it up even more.

Share this post


Link to post
Share on other sites
Also, you are still relying on DOS interrupts:


MOV SI,STRING
CALL PR_STRING
MOV AH,00h
INT 16h
INT 20h

AH=0 INT 20h is a DOS interrupt, not BIOS. Use a HLT instruction to terminate instead.

INT 16h returns the scancode in AH, so INT 21h will execute some random
interrupt. I dont think you want this[smile]

Also, CALL pushed the return address on the stack, but you havnt set up
a stack yet.

Share this post


Link to post
Share on other sites
Quote:
Original post by Crypter
Also, you are still relying on DOS interrupts:


MOV SI,STRING
CALL PR_STRING
MOV AH,00h
INT 16h
INT 20h

AH=0 INT 20h is a DOS interrupt, not BIOS. Use a HLT instruction to terminate instead.

INT 16h returns the scancode in AH, so INT 21h will execute some random
interrupt. I dont think you want this[smile]


i changed that to HLT, forgot to write it here. anyway, whats my environment?

Share this post


Link to post
Share on other sites
Compilier/Linker/emulator etc..

Also, CALL pushes the return address on the stack, but you havnt set up
a stack yet. This could be the problem.

Share this post


Link to post
Share on other sites
Quote:
Original post by Crypter
Compilier/Linker/emulator etc..

Also, CALL pushes the return address on the stack, but you havnt set up
a stack yet. This could be the problem.


im just assembling it in NASM as bin.

How do I set up a stack? I thought it was already set up. Is that because that NASM doesn't use ASSUME?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!