flat assembler
Message board for the users of flat assembler.
Index
> Windows > Buffered Input Help. Goto page 1, 2 Next |
Author |
|
DJ Mauretto 14 Sep 2010, 16:03
Hello
You can use printf and scanf also in 32 asm Code: format PE CONSOLE 4.0 entry start Include 'win32a.inc' section ".code" code readable writeable executable start: PUSH String ; Offset String zero terminated CALL [printf] ADD ESP,4 CALL [getchar] PUSH 0 CALL [ExitProcess] section '.data' data readable writeable String DB 13,10,"Hello World",13,10,0 section '.idata' import data readable writeable library kernel32,'kernel32.dll',\ msvcrt,'msvcrt.dll' import kernel32,\ ExitProcess,'ExitProcess' import msvcrt,\ getchar,'getchar',\ printf,'printf' _________________ Nil Volentibus Arduum |
|||
14 Sep 2010, 16:03 |
|
Overflowz 14 Sep 2010, 16:50
Dude, I know I can use but I need do that without any library. isn't there other way ?.. and anyway I dont need only printf, I need to input string and then output.
|
|||
14 Sep 2010, 16:50 |
|
baldr 14 Sep 2010, 18:00
Overflowz,
scanf() behavior is well-defined, if you need string to-end-of-line, use gets() (but fgets() is safer). ReadFile() from STD_INPUT_HANDLE (you may have to obtain real handle with GetStdHandle() first, to be compliant; XP accepts pseudo-handles raw) by default is buffered (i.e. ENABLE_LINE_INPUT console mode is active). |
|||
14 Sep 2010, 18:00 |
|
Overflowz 14 Sep 2010, 18:53
Mate, I dont like to be depented on msvcrt.dll cause I hate that I'm interested about this code and you'll know what I'm asking I need run 16 bit code in 32 bit program, here's code and you'll understand what I mean. Sry for my bad English. Here's code.
Code: format PE console include 'WIN32AX.INC' entry main .data buffer db ? max db ? .code proc main mov ah,0ah mov dx,max int 21h mov dx,buffer mov ah,09 int 21h endp |
|||
14 Sep 2010, 18:53 |
|
baldr 14 Sep 2010, 19:06
Overflowz,
My english ain't perfect too. Don't be shy about this. DOS ints in Windows executable is a sure way to trouble. Let's do it Win32 API's way: Code: format PE console include "Win32AX.Inc" .code start: invoke WriteFile, STD_OUTPUT_HANDLE, prompt, sizeof.prompt, wbytes, NULL invoke ReadFile, STD_INPUT_HANDLE, input, sizeof.input, rbytes, NULL add [rbytes], sizeof.prefix invoke WriteFile, STD_OUTPUT_HANDLE, prefix, ptr rbytes, wbytes, NULL invoke Sleep, -1 ret struc sized [args] { common . args sizeof.#. = $ - . } .data rbytes rd 1 wbytes rd 1 prompt sized db "Enter something: " prefix sized db "You've entered: " input sized rb 100 .end start |
|||
14 Sep 2010, 19:06 |
|
Overflowz 14 Sep 2010, 20:39
mate I need input/output to print string, not to write in file >.< in 16bit mode in 32bit code. thanks
|
|||
14 Sep 2010, 20:39 |
|
LocoDelAssembly 14 Sep 2010, 20:49
Overflowz, believe me, you SHOULD test the provided code
PS: You'll have to quit the program with Ctrl+C or using the X button. |
|||
14 Sep 2010, 20:49 |
|
Overflowz 14 Sep 2010, 20:53
Oh sorry this is what I need but can this done without "sized" macro ? Cause I dont understand much of macros Thanks.
|
|||
14 Sep 2010, 20:53 |
|
baldr 14 Sep 2010, 20:57
Overflowz,
Definitely it can. This macro expands to Code: name definition sizeof.name = $ - name |
|||
14 Sep 2010, 20:57 |
|
Overflowz 14 Sep 2010, 21:06
Oh, I understand now. Thank you very much! Oh 1 more, what does PTR do ? and also where to get list of handles ? for example that you give me was STD_OUTPUT/INPUT_HANDLE and things like that? Ty!
|
|||
14 Sep 2010, 21:06 |
|
baldr 14 Sep 2010, 21:45
|
|||
14 Sep 2010, 21:45 |
|
Overflowz 14 Sep 2010, 21:51
Thank you. ptr rbytes = [rbytes]. I got it. Thanks for helping !
|
|||
14 Sep 2010, 21:51 |
|
Overflowz 15 Sep 2010, 09:30
Again me Can someone write 16bit example here ? Ty. without dup 24h method >.< and buffer size. Thank you.
|
|||
15 Sep 2010, 09:30 |
|
baldr 15 Sep 2010, 10:05
Overflowz,
Not Win16 example, I hope? Code: org 0x100 mov ah, 0x3F mov cx, sizeof.buffer mov dx, buffer xor bx, bx ; stdin int 0x21 mov cx, ax mov bx, 1 ; stdout mov ah, 0x40 int 0x21 ret buffer rb 100 sizeof.buffer = $-buffer |
|||
15 Sep 2010, 10:05 |
|
Overflowz 15 Sep 2010, 16:57
Ohh, Great method ! Thank you. I have some quiestions about that code. So.. I guess its that method what you wrote in 32bit code. 0x3F = Open File, 0x40 = Write File and xor bx,bx = 0 and how you know that 0 is stdin and 1 stdout ? and also mov cx,ax means it copies size of stdin into cx register for stdout ? and the last question, how to clear screen after input ? Thank you!
|
|||
15 Sep 2010, 16:57 |
|
revolution 15 Sep 2010, 17:01
Overflowz: Use a search engine to search for the DOS interrupts list. (hint: RBIL, Ralf Brown's Interrupt List).
Google is your friend |
|||
15 Sep 2010, 17:01 |
|
Overflowz 15 Sep 2010, 17:23
Well, I searched "Google is your friend" but I cant figure out how to learn that list. It's not understandable for me.. Anyway what's difference between DB and RB ? When I'm trying to do DB code doesn't work and when DB then it works pretty nice. Whats problem ?
|
|||
15 Sep 2010, 17:23 |
|
baldr 15 Sep 2010, 18:17
Overflowz,
RBIL is crucial resource for anybody doing 16-bit programming. There are some cute browsers for it. db defines byte, while rb reserves them. Naturally, «rb x» is equivalent to «db x dup ?». How db can't work? |
|||
15 Sep 2010, 18:17 |
|
Overflowz 15 Sep 2010, 18:29
I dont know.. Just doesn't work.. Anyway thanks for reply!
|
|||
15 Sep 2010, 18:29 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.