flat assembler
Message board for the users of flat assembler.

Index > DOS > garbage and beeping PC speaker

Author
Thread Post new topic Reply to topic
herbally



Joined: 29 Jul 2009
Posts: 4
herbally
I wrote this hello world app that is very simple. I thought that I had everything coded properly, and it compiles and runs without error, but for some reason instead of showing my text string in DOS I get about 3-4 lines of garbage characters and the PC speaker beeps at me on each line. Here's the code:

Code:
format MZ
entry main:START
STACK 100H

segment text
myString: db "I'm a string!",24h

segment main
START:

mov ax, myString
mov ds, ax

mov dx, myString
mov ah, 9
int 21h

mov ah, 4ch
mov al, 00h
int 21h    


Any ideas where I went wrong? Thanks!

Herbally
Post 30 Jul 2009, 16:54
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
mov ax, myString -> mov ax, text

That will fix the issue.

mov ah, 4ch
mov al, 00h

Could be just mov ax, 4c00h.
Post 30 Jul 2009, 16:59
View user's profile Send private message Reply with quote
herbally



Joined: 29 Jul 2009
Posts: 4
herbally
thanks Loco....that did resolve the issue. I'm curious though....what if I had multiple string variables in the text segment? How would the program know which one I am referring to?

Thanks again!
Post 30 Jul 2009, 22:26
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
herbally, not sure what you mean but if you are referring to something like this:
Code:
segment text
string1 db "hello", "$"
value dw $1234    


Then this should work:
Code:
mov ax, text
mov ds, ax ; This shouldn't be done again unless you need to switch to a different data segment and it is not suitable for you using ES segment.

mov cx, [value]  ; CX = 1234h
mov dx, myString ; DX = myString's offset inside "text" segment    
Post 31 Jul 2009, 05:30
View user's profile Send private message Reply with quote
herbally



Joined: 29 Jul 2009
Posts: 4
herbally
To begin with I'm a self-taught VB.NET programmer so my logic as it pertains to assembly is all messed up!

Apparently I was just confused about a very basic part of ASM. I went back and re-read some of the documentation and figured out the answer to my question. Thanks again for your assistance!
Post 31 Jul 2009, 15:46
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.