flat assembler
Message board for the users of flat assembler.

Index > DOS > [trying execute data] can't store a char in db?

Author
Thread Post new topic Reply to topic
theguy



Joined: 22 Jan 2015
Posts: 10
theguy 22 Jan 2015, 11:48
I've looked online and all the examples that i come across(code listed below) say to do this?

Code:
db 'y'    


This will compile but when i try to run the exe it says "NTVDM.EXE has stopped working" and i have to close it, it only happens if i add the code.

In case your wondering what code i have wrote here it is.

Code:
org 100h

db 'y'

Looop:
jmp Looop    


The bare minimum to test "db 'y' " as code is all i wrote.
Post 22 Jan 2015, 11:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 22 Jan 2015, 12:00
COM files begin execution at the very first byte. For your code above the first instruction to be executed to whatever 0x79 disassembles to.

If you want to display 'y' to the screen then you will need to write code to send the character 'y' to the OS to to get it displayed.

You placed this topic in the Windows forum so I don't know how to properly advise because you posted DOS code. If you can confirm whether you want Windows code or DOS code then we can help you better.
Post 22 Jan 2015, 12:00
View user's profile Send private message Visit poster's website Reply with quote
theguy



Joined: 22 Jan 2015
Posts: 10
theguy 22 Jan 2015, 12:05
oops sorry about posting in the wrong forum, yea i'm working with a dos console program.

this code works perfectly fine.

Code:
org 100h 

Looop: 
jmp Looop
    


It just loops and doesn't crash but when i add the db 'y' in the code it will crash and i won't be able to print a char to screen if i can't first store it.
Post 22 Jan 2015, 12:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 22 Jan 2015, 12:16
Store the character below the code:
Code:
org 100h 

Looop: 
jmp Looop

db 'y'    
Post 22 Jan 2015, 12:16
View user's profile Send private message Visit poster's website Reply with quote
theguy



Joined: 22 Jan 2015
Posts: 10
theguy 22 Jan 2015, 12:25
Well that worked! thanks, it's kind of weird because i was following a guy who wrote his code the way i showed you, and it worked for him but maybe it's because he's using linux.
Post 22 Jan 2015, 12:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 22 Jan 2015, 12:29
Even in DOS you can put your data and strings first if you use an EXE format. You also have to tell the assembler where the first instruction is so that the EXE file can tell the OS how to run the code.

It is the COM format that requires the first instruction to be at the beginning of the file. So for you the first instruction was 'y' (0x79, ...) which is clearly not what you wanted.
Post 22 Jan 2015, 12:29
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.