flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > Simple Assembly Program Problem

Author
Thread Post new topic Reply to topic
Mahmoud899



Joined: 26 Sep 2012
Posts: 5
Hello, I am new to the x86 assembly language. I am trying to write a very simple assembly program that prints to the screen a string.

Code:
org 100h

jmp start       ; jump over data declaration

msg:    db      "Hello, World!", 0

start:  
        mov     al, [ds:si]
        cmp     al, 0
        je      done
        mov     ah, 0eh
        int     10h
        inc     si
        jmp     start

done:
        mov ax, 4C00h
        int 21h
    


the program prints the following:
δ♫Hello, World!

I am writing the program on the following assumptions, that any db i make is already put in the data segment, also that the SI, BX, DI are pointing at the data segment. I would like to know why doesn't it print Hello, World! only and it prints weird characters before it?

Thank You
Post 12 Sep 2013, 21:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16128
Location: Hyperborea
You are printing the two bytes of the "jmp start" instruction. Your data follows after the jmp.

You might want to consider initialising SI to point to the data before using it.
Code:
;...
start:
        mov si,msg
loop:
        mov     al, [ds:si]
        cmp     al, 0
        je      done
        mov     ah, 0eh
        int     10h
        inc     si
        jmp     loop
;...    
Post 12 Sep 2013, 22:09
View user's profile Send private message Visit poster's website Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 5983
Location: Poland
Or just do something like that:
Code:
org 100h

jmp start       ; jump over data declaration

msg:    db      "Hello, World!", 0

start:  
        mov     al, [ds:si+2] ; <--- a small change here
        cmp     al, 0
        je      done
        mov     ah, 0eh
        int     10h
        inc     si
        jmp     start

done:
        mov ax, 4C00h
        int 21h     
Post 12 Sep 2013, 22:17
View user's profile Send private message Visit poster's website Reply with quote
Mahmoud899



Joined: 26 Sep 2012
Posts: 5
Thank you guys, problem solved
Post 13 Sep 2013, 11:42
View user's profile Send private message Reply with quote
Mahmoud899



Joined: 26 Sep 2012
Posts: 5
Hello, I am writing a very simple assembly program that adds 2 numbers and then moves their total to a defined variable that I have created

Code:
format MZ

entry .code:start
segment .code
start:
        mov ax, .data
        mov ds, ax
        mov al, data1
        mov bl, data2
        add al, bl
        mov total, al
        mov ah, 4CH
        int 21H 


segment .data
data1   db      52H
data2   db      29H
total   db      ?    


when I assemble the program I get the following error:
F2_1.asm[11]:
mov total, al
error: invalid operand.

How is that possible, it should be possible that you could move data from general purpose registers to a user defined variable. How can I fix that error thank you
Post 13 Sep 2013, 12:39
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671
Mahmoud899

mov al, data1 ;transfers the ADDRESS
mov al, [data1] ;transfers the VALUE

Every time you want to transfer data from or to memory (like your variables), use the brackets like [data] or [ds:data]. Without the brackets, the address is transferred instead.
Post 13 Sep 2013, 12:49
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671
Download "emu8086" so that you can see how your instructions behave against the registers in step-by-step manner. It has direct support of FASM syntax. Start with a simpler flat memory model like org. It provides you with a natural transition to flat 32-bit programming.
Post 13 Sep 2013, 13:06
View user's profile Send private message Reply with quote
Mahmoud899



Joined: 26 Sep 2012
Posts: 5
I tried your suggestion and edited the code and inserted square brackets around data1 and data2 and I am still getting the same problem in the same line. I have tried it on the EMU8086 and it also gave me the same error. I am also using 16-bit programming not 32-bit
Post 13 Sep 2013, 13:21
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671
[total]
Post 13 Sep 2013, 13:30
View user's profile Send private message Reply with quote
Mahmoud899



Joined: 26 Sep 2012
Posts: 5
excellent it worked. Thanks for the help
Post 13 Sep 2013, 13:51
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
What about overflow / carry flag ?
You should interprete this.
Try to add 0FFh and 80h and see what happens ... Cool
Post 13 Sep 2013, 15:12
View user's profile Send private message Send e-mail 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-2018, Tomasz Grysztar.

Powered by rwasa.