flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Problem on second use of print text macro

Author
Thread Post new topic Reply to topic
oscar



Joined: 01 Feb 2006
Posts: 5
oscar
Hi,

I am trying to write a macro to print a line of text to teh screen (In bios mode) but i seem to only be able to work once then if i call it again it doesn't print anything. It compiles fine, but it just doesn't run properly...can anyne PLEASE help me lol

thanks


P.S. Here's my problem code:

Code:
org 0x7c00
use16
                mov ax, 0x0000
                mov ds, ax

start:

macro print String{

        local .Printer
        local .Nextchar
        local .Return
        local a

        .Printer:
                mov si, a
                mov ah, 0Eh
                jmp .Nextchar
        
        .Nextchar:
                lodsb
                or al, al
                jz .Return
                int 10h
                jmp .Nextchar
                
        .Return:
                ret
        
        a db String,10,13,0
}

print "haha"
print "akimbo"

times 505-($-start) db 0  512 bytes
dw 0xaa55
    
Post 11 Feb 2006, 13:08
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17341
Location: In your JS exploiting you and your system
revolution
The first instantiation of the macro will print "haha" and then RETurn to the caller (BIOS) so ANY code you place after your macro will not be executed. Try this:
Code:
org 0x7c00
use16 
                mov ax, 0x0000 
                mov ds, ax 

start: 

macro print String{ 

        local .Printer 
        local .Nextchar 
        local .Done
        local .a

        .Printer: 
                mov si, .a
                mov ah, 0Eh 
                jmp .Nextchar 
         
        .Nextchar: 
                lodsb 
                or al, al 
                jz .Done
                int 10h 
                jmp .Nextchar
                jmp .Done

        .a db String,10,13,0

        .Done:
} 

print "haha" 
print "akimbo"
      ret

times 505-($-start) db 0  ;512 bytes
dw 0xaa55    


BTW: does the follwing line really compile properly?
Code:
times 505-($-start) db 0  512 bytes    
I get an error,
Post 11 Feb 2006, 15:06
View user's profile Send private message Visit poster's website Reply with quote
oscar



Joined: 01 Feb 2006
Posts: 5
oscar
it does....but it may not actually be 512 bytes...i saw it in an example i was looking at and i never actaully figured out if stuff in the bootsector HAS to be 512 bytes or if it can be less than that.

point being it compiles for me...sould be
Code:
times 505-($-start) db 0 ;512 bytes    

(the 512 bytes was a comment)

anyway,

Thanks heaps, i had the idea that "ret " just returned you to where you were in the main program (kind of like an exit in BASIC).

i can't beleive i spent 2 days trying to figure out something so simple
Post 11 Feb 2006, 22:46
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
oscar: I think you are using the macro where what you wanted was actually the procedure. The fact that you used "called" terminology and "ret" instruction seems to confirm it.
Post 12 Feb 2006, 06:24
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17341
Location: In your JS exploiting you and your system
revolution
Quote:
i never actaully figured out if stuff in the bootsector HAS to be 512 bytes or if it can be less than that.
It must be 512 bytes to match the HDD sector size. The "dw 0xaa55" is also needed as the last two bytes to show the BIOS that the data is valid and not a blank sector.
Post 12 Feb 2006, 10:42
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.