flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2, 3 Next |
Author |
|
FlierMate 17 Apr 2022, 16:31
If I change from rcx to rax, this actually works as well:
Code: addition: fastcall [printf], add_ fastcall [scanf],'%d',operand1 fastcall [scanf],'%d',operand2 mov rax, [operand1] add rax, [operand2] fastcall [printf],'%d', rax |
|||
![]() |
|
retro 17 Apr 2022, 16:32
ah, now the calculator itself is working!
note that i said the calculator itself, not the whole program... now i have to fix that problem where after the user presses any key to continue the program, the program simply exits. i think what's happening is that the program is ignoring the getchar at the beginning, but why's it doing that? |
|||
![]() |
|
retro 17 Apr 2022, 16:35
> If I change from rcx to rax, this actually works as well:
is there a "best" register to use in this case? or it doesn't matter at all and i can use any register for this calculator? i'm guessing in an integer calculator like mine, it shouldn't matter what register it's using, but in float/ double calculators it would matter a lot. |
|||
![]() |
|
macomics 17 Apr 2022, 16:37
scanf does not clear the input characters before returning. i.e. "\n" remains in the buffer. And you react to this by exiting the program. Replace Enter with any letter key and you will see. For integer calculations, you can use any free general-purpose register (i.e. except rsp)
Last edited by macomics on 17 Apr 2022, 16:40; edited 1 time in total |
|||
![]() |
|
FlierMate 17 Apr 2022, 16:38
retro wrote: > If I change from rcx to rax, this actually works as well: The macroinstruction overrides the rcx? Code: macro fastcall proc,[arg]..... Though someone more knowledgeable should be able to give a better explanation. ![]() Last edited by FlierMate on 17 Apr 2022, 16:43; edited 1 time in total |
|||
![]() |
|
retro 17 Apr 2022, 16:41
> scanf does not clear the input characters before returning. i.e. "\n" remains in the buffer. And you react to this by exiting the program. Replace Enter with any letter key and you will see.
i was guessing that right now, apparently i was right. so, do i have to xor al, al at the beginning of the program so the register gets cleared and then the user can go back to the menu and perform what they want? |
|||
![]() |
|
macomics 17 Apr 2022, 16:43
Both FPU and SSE can be used for floating-point calculations.
retro wrote: > scanf does not clear the input characters before returning. i.e. "\n" remains in the buffer. And you react to this by exiting the program. Replace Enter with any letter key and you will see. |
|||
![]() |
|
FlierMate 17 Apr 2022, 16:50
I am not sure if you can make use of _kbhit
|
|||
![]() |
|
retro 17 Apr 2022, 16:51
maybe i can, i think i can also use _getch.
|
|||
![]() |
|
retro 17 Apr 2022, 17:08
there, the calculator is almost completed, the only problem is in the division part:
after the user types in the 2 numbers, the program hangs for a second and crashes. i think i'll search for a division code on the internet and see if i can adapt it to my design. |
|||
![]() |
|
retro 17 Apr 2022, 17:21
couldn't find on the internet, so i decided to check on the debugger to see what's wrong with it:
"40128D: Integer overflow (exc.code c0000095, tid 11028)". hmm... |
|||
![]() |
|
macomics 17 Apr 2022, 17:21
Code: mov rax, [operand1] cdqe ; rdx = sign(rax) i.e. 0 or -1 idiv [operand2] mov [answer], rax mov [remains], rdx |
|||
![]() |
|
retro 17 Apr 2022, 17:37
well, it didn't work for me, the program still hangs and crashes after typing in 2 numbers at the division part...
|
|||
![]() |
|
macomics 17 Apr 2022, 17:41
Then you can give the code that you wrote and where exactly you have a problem. Fortune-telling on coffee grounds is not the best way to help.
|
|||
![]() |
|
retro 17 Apr 2022, 17:51
Code: division: xor rax, rax xor rcx, rcx fastcall [printf], div_ fastcall [scanf],'%d',operand1 fastcall [scanf],'%d',operand2 mov rax, [operand1] cdqe ; rdx = sign(rax) i.e. 0 or -1 idiv [operand2] fastcall [printf],'%d', rax fastcall [printf],'%d', rdx call [getch] jmp start and apparently, from what i saw in the debugger, the problem is in "idiv [operand2]". |
|||
![]() |
|
macomics 17 Apr 2022, 18:18
Code: mov rcx, [operand2] mov rax, [operand1] cdqe jrcxz div_by_zero ; div-by-0 idiv rcx ; fastcall [printf],'%d', rax sub rsp, 32 mov rdx, rax ; remains - disappear jmp @f .str0 db "%d", NULL @@: lea rcx, [.str0] call [printf] add rsp, 32 ; fastcall [printf],'%d', rdx sub rsp, 32 ; mov rdx, rdx <- unused jmp @f .str1 db "%d", NULL @@: lea rcx, [.str1] call [printf] add rsp, 32 ... div_by_zero: fastcall [printf], "Div by 0!" Last edited by macomics on 17 Apr 2022, 18:38; edited 1 time in total |
|||
![]() |
|
FlierMate 17 Apr 2022, 18:25
I have a shorter version: (I am not sure why CDQ worked but not CDQE)
Code: division: xor rax, rax ;xor rcx, rcx fastcall [printf], div_ fastcall [scanf],'%d',operand1 fastcall [scanf],'%d',operand2 mov rax, [operand1] cdq ; rdx = sign(rax) i.e. 0 or -1 idiv [operand2] fastcall [printf],'%d', rax |
|||
![]() |
|
macomics 17 Apr 2022, 18:30
I'm always confused which one is 32-bit.
Code: CDQE ; rax = uuuu`uuuu`svvv`vvvv; rdx = 0000`0000`yyyy`yyyy CDQ ; rax = svvv`vvvv`vvvv`vvvv; rdx = yyyy`yyyy`yyyy`yyyy ; u - undef hex-digit ; s - sign hex-digit ; y - sign bits (0 or F) ; v - value hex-digit |
|||
![]() |
|
FlierMate 17 Apr 2022, 18:41
macomics wrote: I'm always confused which one is 32-bit. I see, both is:convert doubleword to quadword cdq Code: %eax -> %edx:%eax cdqe Code: %eax -> %rax This is my first time encounter with CDQE. Good to learn from you. |
|||
![]() |
|
Goto page Previous 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.