flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
bitRAKE 31 Mar 2021, 14:01
There are many ways to move forward. Beginning at the start of the buffer, convert digits and stop when a non-digit is reached. Another way is to scan from the end of the string with the [count] returned.
Presently you are getting the address in EAX of the buffer. A number would be in the range '0' to '9'. Code: cmp byte [rax],'0' jc .too_low cmp byte [rax],'9'+1 jnc .too_high ; now there is a digit at byte [rax] |
|||
![]() |
|
FlierMate 02 Apr 2021, 12:34
ughisuck wrote:
Hi, I am learning too. I have modify your code a little bit so that now it can add any two single-digit numbers! Code: HANDLEADD: push r12 push r13 invoke WriteConsole,[stdout],addr sAdd,sAddSz,addr outSz,0 invoke ReadConsole,[stdin],buff,1024,addr count,0 ; mov eax,buff ; push buff ; mov by ; push qword [eax] ; push count-2 movzx r12, byte [buff] sub r12, 48 ; ask for second number invoke WriteConsole,[stdout],addr sAdd2,sAdd2Sz,addr outSz,0 invoke ReadConsole,[stdin],buff,1024,addr count,0 movzx r13,byte [buff] sub r13, 48 ; add it! add r12,r13 invoke wsprintf,result,'%d',r12 invoke WriteConsole,[stdout],result,4,addr outSz,0 pop r13 pop r12 jmp clear HANDLESUB: ...... ...... .data buff rb 1024 buff2 rb 1024 result rb 64 Just to serve as an not-so-good example.
|
||||||||||
![]() |
|
FlierMate 02 Apr 2021, 14:22
This is my new code, with reference to other sources on how to convert string to integer.
Code: HANDLEADD: push r12 push r13 invoke WriteConsole,[stdout],addr sAdd,sAddSz,addr outSz,0 invoke ReadConsole,[stdin],buff,1024,addr count,0 ; mov eax,buff ; push buff ; mov by ; push qword [eax] ; push count-2 call convert mov r12d, eax ;movzx r12, byte [buff] ;sub r12, 48 ; ask for second number invoke WriteConsole,[stdout],addr sAdd2,sAdd2Sz,addr outSz,0 invoke ReadConsole,[stdin],buff,1024,addr count,0 ;movzx r13,byte [buff] ;sub r13, 48 call convert mov r13d,eax ; add it! add r12d,r13d invoke wsprintf,result,'%d',r12d invoke WriteConsole,[stdout],result,6,addr outSz,0 pop r13 pop r12 jmp clear convert: xor eax,eax lea ebx, [buff] .redo: movzx ecx, byte [ebx] inc ebx cmp ecx, '0' jb .done cmp ecx, '9' ja .done sub ecx, '0' imul eax, 10 add eax,ecx jmp .redo .done: ret
|
||||||||||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.