flat assembler
Message board for the users of flat assembler.

Index > DOS > Question

Author
Thread Post new topic Reply to topic
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr 18 Feb 2007, 21:20
When compiling this program the screen flashes black for a second then executes. How can I make it so it doesn't flash?
Code:
org 256

jmp main

string db 'Hello World!', 0
crlf db 0x0D, 0x0A, '$'

write:
    mov ah, 2
    .loop:
        mov al, [si+bx]
        or  al, al
        jz  .done
        mov dl, al
        int 33
        inc bl
        jmp .loop
    .done:
        mov bx, 0
        call endl
        ret

endl:
    mov ah, 9
    mov dx, crlf
    int 33
    ret

main:
        mov si, string
        call write

        mov [string+3], 'p'
        mov [string+4], '!'
        mov [string+5], 0

        mov si, string
        call write

        int 32    
Post 18 Feb 2007, 21:20
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 18 Feb 2007, 21:40
I assume you're using FASMW? In that case, use the Win32 console version (FASM.EXE, approx. 77k) in a CMD.EXE window (Start -> Run -> cmd.exe -> cd /d c:\fasm && fasm c:\projects\jake.asm ).
Post 18 Feb 2007, 21:40
View user's profile Send private message Visit poster's website Reply with quote
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr 18 Feb 2007, 22:50
Why does this refuse to work?
Code:
org 256
jmp Main

  get db 0

write:
    push ax bx dx
    mov ah, 2h
    mov bx, 0
    .loop:
        mov al, [si+bx]
        or  al, al
        jz  .done
        mov dl, al
        int 21h
        inc bl
        jmp .loop
    .done:
        mov bx, 0
        call endl
        pop dx bx ax
ret

endl:
    push ax dx
    mov ah, 2
    mov dl, 0Dh
    int 33
    mov dl, 0Ah
    int 33
    pop dx ax
ret

read:
    push ax bx dx
    .input:
        mov ah, 8
        int 21h

        cmp al, 13
        je .complete

    .continue:
        mov ah, 2
        mov dl, al
        int 21h

        mov [get+bx], al
        inc bl
        jmp .input

    .complete:
        mov [get+bx], 0
        mov ax, get
        call endl
        pop dx bx ax
ret

Main:
call read
mov si, ax
call write

int 32    

It says it attempted an illegal opperation when run. (or won't print)
Post 18 Feb 2007, 22:50
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 19 Feb 2007, 01:50
Jakefvr: maybe you are forgetting to initialize BX in "read"?
Post 19 Feb 2007, 01:50
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr 19 Feb 2007, 03:32
It still doesn't work, it works just fine if I do one without the other, but together they just refuse to work Sad
Post 19 Feb 2007, 03:32
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 19 Feb 2007, 10:36
Jakevfr:

Code:
mov si, ax 
call write    

what is value of ax supposed to be?
Post 19 Feb 2007, 10:36
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr 19 Feb 2007, 16:20
The string entered in read.

EDIT: Well I changed it so that it wouldn't pop AX off of the stack, but it still won't work :[ Here's the code now:

Code:
org 256
jmp Main

  get db 0

write:
    push ax bx dx
    mov ah, 2h
    mov bx, 0
    .loop:
        mov al, [si+bx]
        or  al, al
        jz  .done
        mov dl, al
        int 21h
        inc bl
        jmp .loop
    .done:
        mov bx, 0
        call endl
        pop dx bx ax
ret

endl:
    push ax dx
    mov ah, 2
    mov dl, 0Dh
    int 33
    mov dl, 0Ah
    int 33
    pop dx ax
ret

read:
    push bx dx
    mov bx, 0
    .input:
        mov ah, 8
        int 21h

        cmp al, 13
        je .complete

    .continue:
        mov ah, 2
        mov dl, al
        int 21h

        mov [get+bx], al
        inc bl
        jmp .input

    .complete:
        mov [get+bx], 0
        mov ax, get
        call endl
        pop dx bx
ret

Main:
call read
mov si, ax
call write

int 32
    
Post 19 Feb 2007, 16:20
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 19 Feb 2007, 16:37
1. "get" buffer should be larger than just one byte

2. what is "read" supposed to return in AX?
Post 19 Feb 2007, 16:37
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr 19 Feb 2007, 17:07
It is supposed to return the buffer get. So when the user inputs something what they inputed is placed into get, and then placed in ax.
Post 19 Feb 2007, 17:07
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 19 Feb 2007, 19:10
so then the problem is 1)

"get db 0" declares one byte. You need more bytes, otherwise you will overwrite following things, in your case code of "write" procedure.
Post 19 Feb 2007, 19:10
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr 19 Feb 2007, 20:09
Thank you. The reason I didn't see that until you basically pointed it out to me is because this is what I get looked like before I began the functions smaller.
Code:
get db 100 dup (?)    

Looking back at earlier posts I see I changed that.

Thanks again vid
Post 19 Feb 2007, 20:09
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 19 Feb 2007, 21:53
Jakefvr: you are welcome.

There is one more challenge: don't allow "read" to overflow buffer. Accept at most so many chars, that buffer won't overfow
Post 19 Feb 2007, 21:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr 19 Feb 2007, 22:27
Alright, I'll do that.
Post 19 Feb 2007, 22:27
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.