flat assembler
Message board for the users of flat assembler.
Index
> DOS > EXE vs COM | Dos Read String/Output String Error Goto page 1, 2 Next |
Author |
|
drewtoby 10 Mar 2012, 21:09
Hello, I am new to dos and am working on a basic dos code inspired by: http://www.skynet.ie/~darkstar/assembler/tut5.html
Only I want mine to read a 15 character input and then output it to the screen. Nothing too hard. However, I keep getting an invalid operand error at Code: mov b[bx],'$' My full code is below: Code: format binary as "exe" org 0x100 Start: ;Setup String ------------------------------------------------------ mov bx,offsetnumber+7 ; put a $ at end of buffer. mov b[bx],'$' ; we will fill buffer from back forwards dec bx ;Input String ------------------------------------------------------ mov dx,offsetnumber mov ax,dx mov b[bx],15 int 21h mov [bx], ax ;Print String-------------------------------------------------------- mov ax,09 int 21h ;Exit --------------------------------------------------------------- mov al,00 int 21h Thanks in advance for your help!!!!! EDIT by DOS386 : enhanced subject |
|||
10 Mar 2012, 21:09 |
|
Coty 10 Mar 2012, 21:42
Also note that FASM does not use the "offset" operand!
So when you type: Code: start: mov dx,offset number mov bx,dx Do not type offset instead just type: Code: start: mov dx, number mov bx,dx |
|||
10 Mar 2012, 21:42 |
|
drewtoby 10 Mar 2012, 22:03
Great, thanks!!! Almost compiles, but one last error at:
Code: mov byte[bx],ax Operand Sizes Do Not Match =( Should I change the ax register? If so, to what? If not, what do I do to fix? |
|||
10 Mar 2012, 22:03 |
|
Coty 10 Mar 2012, 22:15
I might start with a more simple tutorial on assembly language.
AX is a 16bit register. byte tells the assembler you want to move 8bit data into [bx] thus you can not tell FASM to move 16bit as an 8bit data byte == 8bit data word == 16bit data also, you may cheat FASM with simply Code: mov [bx], ax as FASM already knows that AX is 16bit HOWEVER it is good to note using this in your code will not give you your desired result ===================================================== Here, I started with this ZIP tutorial:
|
|||||||||||
10 Mar 2012, 22:15 |
|
drewtoby 10 Mar 2012, 23:14
Thanks for the tutorial! However, I would like to finish my code below before I change tutorials =)
I got the following code to compile, but it will not stay open (even when I remove the exit code). When I enter it in cmd, and then a number or two after it, the program will do nothing What do I need to finish it!? Code: format binary as "exe" org 0x100 Start: ;Setup String ------------------------------------------------------ mov bx,dx ; put a $ at end of buffer. mov word[bx],'$' ; we will fill buffer from back forwards dec bx ;Input String ------------------------------------------------------ mov bx,dx mov ax,dx mov word[bx],15 int 21h mov word[bx],ax ;Print String-------------------------------------------------------- mov ax,09 int 21h ;Exit --------------------------------------------------------------- mov al,00 int 21h |
|||
10 Mar 2012, 23:14 |
|
Coty 10 Mar 2012, 23:23
It is exiting to fast before you can see it, try launching it from the command prompt. or before any exitcode add this:
Code:
stay:
jmp stay Of course the program will only exit it if you force quite, or if you are running pure DOS, just hit the off switch. |
|||
10 Mar 2012, 23:23 |
|
typedef 10 Mar 2012, 23:26
add this code after or before ;Exit --------------------------------------
Code: xor ax, ax int $16 |
|||
10 Mar 2012, 23:26 |
|
typedef 10 Mar 2012, 23:30
Coty wrote: pure DOS, just hit the off switch. lol Windows 8 is similar to pure DOS Offtopic: by the way Windows 8 saved my computer. I was making a personal firewall that hooks all processes on startup and I kept BSODing my System even in Safe mode and recovery console. So I used that Win8 I got from you to repair my PC back. Cool story |
|||
10 Mar 2012, 23:30 |
|
Coty 11 Mar 2012, 00:04
^ No because people actually WANTED DOS
And you used windows 8 to repair XP? I'd be afraid it would screw something up |
|||
11 Mar 2012, 00:04 |
|
shutdownall 11 Mar 2012, 01:34
Try this:
Code: format binary as "EXE" org 0x100 Start: ;Print String-------------------------------------------------------- mov dx,msg mov ah,09 int 21h mov bl,10 loop1: mov ah,01 int 21h dec bl jnz loop1 jmp exit ;Exit --------------------------------------------------------------- msg db 'DOS started ...,',0dh,0ah,'$' exit: You need to put function of int 21 in ah value, not ax. This is not the same. That's why you not see something. If you put 09h in ax, then al will have 09h and ah will have 00h which means exit. The program prints a starting message and you can type in 10 chars/keys, then program stops/ends. Find out how it works. |
|||
11 Mar 2012, 01:34 |
|
revolution 11 Mar 2012, 01:58
Just one thing here. This line is entirely unneeded:
Code: format binary as "exe" |
|||
11 Mar 2012, 01:58 |
|
drewtoby 11 Mar 2012, 03:54
@shutdownall: Thanks for your code! I changed ax to ah, and I am closer still (error posted below)! I did not know that I was forcing ax to close the program
How does the bl register control the # of chars? The ah register is set at 09 so user can input, and the 01 is for each letter entered one at a time in the loop, but the value is not stored in ah, right? How would you get the ah register to store the chars for when the user hits enter? Would that be the byte/word statements, followed by the number of charectors in the string with ah in []? So if I would have your program store the input I would change the 01 from the loop to 09? And then add a variable equal to zero, which ax would move the value to, and then move that to dx after enter is called (after first int21h)? @revolution: I would like the file to be executable, not in .com format. Thanks though. @typedef & Coty: I tried your codes, but they did not change anything. It does something now at least, and that thing is outputting random symbols and beeping once when you uncomment my line with ax/db . Now what am I doing wrong? Just overloading a register, or corrupting it with a bad value!? Code: format binary as "exe" org 0x100 Start: ;Setup String ------------------------------------------------------ mov bx,dx ; put a $ at end of buffer. mov byte[bx],'$' ; we will fill buffer from back forwards dec bx ;Input String ------------------------------------------------------ mov bx,dx ;mov ax,dx THIS IS THE LINE THAT CAUSES BEEPING AND SYMBOLS!!!!!!! mov byte[bx],15 int 21h mov byte[bx],ah ;Print String-------------------------------------------------------- mov ah,09 int 21h ;stay: ; jmp stay ;Exit --------------------------------------------------------------- ;xor ax, ax ;int $16 mov al,00 int 21h |
|||
11 Mar 2012, 03:54 |
|
drewtoby 11 Mar 2012, 04:31
@shutdownall: tried to get your code to display 0 after any string has been entered, only the zero will display over and over again once a char is entered. Well, it has the beeping and random chars (charector) outputs over and over again . Just like my code above
Code: format binary as "EXE" org 0x100 Start: ;Print String-------------------------------------------------------- mov ah,09 ;start with input int 21h ;call the interupt dec bl ;have dl register limit string to 10 chars mov bl,10 ;finishing ^ mov dx, msg ;has dx display 0, in theory int 21h ;interupt msg db '0' ;the zero, held in a variable So what can I do to fix both of my codes, anyone? |
|||
11 Mar 2012, 04:31 |
|
typedef 11 Mar 2012, 05:45
You said you want an EXE, Console
Code: format PE CONSOLE ; EXE, include 'win32ax.inc' entry main section '.txt' code readable executable main: invoke SetConsoleTitle,'My cool console app' invoke GetStdHandle,STD_INPUT_HANDLE mov [hConsole], eax invoke GetStdHandle,STD_OUTPUT_HANDLE mov [hConsole+4], eax ; read something, about 255 bytes max invoke ReadFile,dword[hConsole+(0*4)],pszBuffer,255,ebx,NULL ; write it to the ouput handle ; ebx = bytes read invoke WriteFile,dword[hConsole+(1*4)],pszBuffer,dword[ebx],ebx,NULL cinvoke system,'pause' ret section '.idata' import data readable library kernel32,'kernel32.dll',msvc,'msvcrt.dll' ; <---- Standard version import msvc,\ system,'system' include 'api/kernel32.inc' section '.dada' data readable writeable pszBuffer db 256 dup(0) ; 255 hConsole: dd 0 ; STD_IN dd 0 ; STD_OUT |
|||
11 Mar 2012, 05:45 |
|
typedef 11 Mar 2012, 05:46
But this is DOS section ?
So you actually want an MZ, but wait and MZ is .COM WTF ?! |
|||
11 Mar 2012, 05:46 |
|
typedef 11 Mar 2012, 06:30
Ok, I'll jusy lay them out you'll chose the one you like. Here's something for you to study this weekend.
Code: org $100 mov bx, prompt mov cx, plen call prints mov bx, buffer mov cx, 90 call gets mov cx, ax ; use returned number of bytes read mov bx, buffer call prints call getc call quit ; bx = buffer ; cx = len prints: .p: cmp cx, 0 je .d mov dl, byte[bx] mov ah, 02 int $21 inc bx dec cx jmp .p .d: ret buffer db 1024 dup(0),'$' prompt db 'PASSWORD: ' plen = $ - prompt quit: mov ah,$4c int $21 ret ; cx = buffer length ; bx = buffer address ; terminate when $D is encountered ; returns number of bytes read gets: push cx .get: push cx ; save on cross call call getc pop cx cmp al, $D ; return je .fin mov byte[bx], al inc bx dec cx jnz .get .fin: pop ax sub ax,cx ; ax = bytes read ret ; al = key read getc: xor ax, ax int $16 ret |
|||
11 Mar 2012, 06:30 |
|
revolution 11 Mar 2012, 08:10
drewtoby wrote: @revolution: I would like the file to be executable, not in .com format. Thanks though. Code: format mz What you have now is a .com file but with a .exe name. You are being fooled into thinking you have a .exe file, when actually you don't. Last edited by revolution on 11 Mar 2012, 09:01; edited 2 times in total |
|||
11 Mar 2012, 08:10 |
|
revolution 11 Mar 2012, 08:12
typedef wrote: So you actually want an MZ, but wait and MZ is .COM |
|||
11 Mar 2012, 08:12 |
|
DOS386 11 Mar 2012, 09:26
revolution wrote:
> Then you want to use: > format mz > But then you will need to include sections references > See the "multiseg" MZ file example NO. Segments/sections are not obligatory. Don't look at typedef's posts, they are bullshit. DOS COM - format binary, org $0100 DOS MZ EXE - format MZ or (format binary but brew headers manually), org 0 Win32 PE EXE - format PE or (format binary but brew headers manually), org $0040'1000 DOS is dumb so your "format binary org $0100" may work, but it's faulty. Anyway, make sure to use proper format and proper subforum matching your OS If you want to use Windows 8 (or any other Windows version from - infinity to + infinity) then use format PE , see included example or http://board.flatassembler.net/topic.php?t=11172 _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
11 Mar 2012, 09:26 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.