flat assembler
Message board for the users of flat assembler.

Index > Linux > 64-bit Numeric Recognition

Author
Thread Post new topic Reply to topic
donn



Joined: 05 Mar 2010
Posts: 321
donn 01 Jul 2010, 04:25
Hi, I've some lines I wrote but can't figure out how the Comp will recognize a '1' or a '2' from the keyboard, then make a decision based on it.

I started off with loading '1' or '2' for the Comp to compare with 'Answers' which should be a '1' or a '2'. I think 11111b is '1' and 100000b is 2. Tried that first, but when it came time for A1 or A2 to be displayed, or C11 or C12, etc for that matter, the Comp displays as if the message 1 was entered. So then I tried ONE db '1',0 then ONE dd 1, and a lot of combinations, but couldn't get it to work.

Code:
mov r12, ONE         ;mov r12, 11111b        ;LOAD COMPARE 1
mov r13, TWO         ;mov r13, 100000b       ;LOAD COMPARE 2
mov rdx, [stdin]

SectionP1:               ;PRINT INITIAL MSG
mov rdi, P1
xor eax, eax
call printf

mov rsi, Answers
mov rdi, AnswerFormat
xor eax, eax
call scanf

SectionCMP1:
mov r14, Answers
cmp r14, r12
je SectionA1
cmp r14, r13
je SectionA2

SectionA1:
mov rdi, A1
xor eax, eax
call printf
mov rsi, Answers
mov rdi, AnswerFormat
xor eax, eax
call scanf
jmp SectionCMP2

SectionA2:
mov rdi, A2
xor eax, eax
call printf
mov rsi, Answers
mov rdi, AnswerFormat
xor eax, eax
call scanf
jmp SectionCMP3
    


Hm, any ideas? I can provide any more information if necessary.

Have a good night,
Denat
Post 01 Jul 2010, 04:25
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 01 Jul 2010, 04:47
In a quick look I see you are "reading" the values with "mov r14, Answers", it should actually be "mov r14, [Answers]" (i.e. compare the contents of Answers, not the pointer).

The comparison still is not good, a character takes one byte (or two but I believe these C functions return 8-bit chars), so you should either load [Answers] in a byte register or just doing the comparison directly (cmp byte[Answers], '1'). You have not provided the format string, in case it wasn't %c but %d instead then you should use a dword register or use "cmp dword[Answers], 1".

About the extra info if possible please provide a compilable code so we can better assist you in the solution instead of providing you best guesses. Please always do this! Smile
Post 01 Jul 2010, 04:47
View user's profile Send private message Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 28 Jul 2010, 21:56
Hey, yeah the contents [answers] works. Here's what I used for the compare section, from your advice, :

Code:
cmp byte[Answers], 1
je SectionA1
cmp byte[Answers], 2
je SectionA2    


The application works fine, you helped a ton! That's my first application I wrote, all the information you provided made it work very quickly. A huge help. I have it attached in 32 and 64 bit versions. I have 64bit machine but 32 works, not sure if it works on 32 machine. Any idea of how to get it to run on Windows? There a win32 argument for fasm and gcc? I couldnt find one. So here it is, its a text game for console. Hm, can't load the executable from this mac as attachment, just the .asm's.

Have a good one,
Denat


Description:
Download
Filename: Paths32.asm
Filesize: 10.78 KB
Downloaded: 595 Time(s)

Description:
Download
Filename: Paths64.asm
Filesize: 11.02 KB
Downloaded: 599 Time(s)

Post 28 Jul 2010, 21:56
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 29 Jul 2010, 06:56
denat, I couldn't test it here yet but seems well done. The only problem I see is that you forgot to add to ESP as much arguments as you pushed multiplied by 4. (This is for the 32-bit version only)

To improve this program I suggest you to build some data structure to hold all the messages and then walk the structure according to user's answers. I haven't checked very carefully but it looks that there are no cycles so a binary tree seems appropriate for this program.

As for Windows, you better check the Windows forum for examples using msvcrt. In Windows is much easier to get executables as fasm can produce them straight. Well, with the latest extensions to fasm you can actually make ELF executables that links to shared objects, but it is still not as easy as with the Windows package with its macros. If you want the linker way, you have to use "format MS COFF" and download the LIBs and linker from somewhere.
Post 29 Jul 2010, 06:56
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.