flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
JohnFound 30 Jan 2015, 20:40
You need to convert the register to string and then to write the string to the console using sys_write system call (#4), with file descriptor = 1 (STDOUT) or 2 (STDERR).
|
|||
![]() |
|
ed_crumbpacker 30 Jan 2015, 22:02
that's exactly what I'm trying to do. I have puppy linux so fasm is the only compiler (no c stuff). Every example I find uses printf or some other stuff. I tried 5 to 6 different methods but they all blow up or put out nothing and without a debugger I can't tell whats happening.
|
|||
![]() |
|
RIxRIpt 30 Jan 2015, 22:55
Code: ;Prints RAX to STDOUT display_reg: lea rsi, [str_reg + 16] .loop: mov cl, al shr rax, 4 and cl, 0x0F dec rsi add cl, '0' cmp cl, '9' jbe @f add cl, 'a' - '9' - 1 @@: mov [rsi], cl test rax, rax jnz .loop mov edx, 17 lea rsi, [str_reg] mov edi, STDOUT mov eax, sys_write syscall ret |
|||
![]() |
|
ed_crumbpacker 30 Jan 2015, 23:30
OK I had to change r to e because I'm 32-bit and created a str_reg as db ? (not sure if thats right). Is mov edi,STDOUT correct? Anyway I get a segmentation fault
Code: format ELF executable entry display_reg str_reg db ? ;Prints RAX to STDOUT display_reg: mov eax,0x423f lea esi, [str_reg + 16] .loop: mov cl, al shr eax, 4 and cl, 0x0F dec esi add cl, '0' cmp cl, '9' jbe @f add cl, 'a' - '9' - 1 @@: mov [esi], cl test eax, eax jnz .loop mov edx, 17 lea esi, [str_reg] mov ebx, 1 mov eax, 4 int 0x80 _eoj: ;exit to LINUX mov eax,1 xor ebx,ebx int 0x80 another question...how do I get my code into one of those cool white boxes? Edit by revolution: You now have a "cool white box" |
|||
![]() |
|
revolution 30 Jan 2015, 23:36
You need to make your buffer area larger to store the string:
Code: str_reg rb 32 ;make space for the entire string |
|||
![]() |
|
ed_crumbpacker 31 Jan 2015, 05:10
thanks for the help...so this is the final outcome. When I run it all the register come out with about to same numbers
eax 8048054 ebx 8048058 ecx 804805C edx 8048060 This seems suspicious to me...I'll keep playing with it Code: format ELF executable entry _start reg_eax rd 1 reg_ebx rd 1 reg_ecx rd 1 reg_edx rd 1 prt_str db 'e' reg_id db ' ' db 'x:' str_reg rb 32 str_end db 0xa str_reg_size = $-prt_str _start: mov [reg_eax],eax ;save off registers mov [reg_ebx],ebx mov [reg_ecx],ecx mov [reg_edx],edx mov eax,reg_eax mov [reg_id],'a' ;place the reg letter in label call display_reg mov eax,reg_ebx mov [reg_id],'b' call display_reg mov eax,reg_ecx mov [reg_id],'c' call display_reg mov eax,reg_edx mov [reg_id],'d' call display_reg jmp _eoj display_reg: lea esi, [str_reg + 16] .loop: mov cl, al ;mov byte shr eax, 4 ;remove small byte and cl, 0x0F ; dec esi ; add cl, '0' ;ex. if cl = 2 + 48 = 50 (ascii '2') cmp cl, '9' jbe @f add cl, 'a' - '9' - 1 ;ex. 97 - 57 - 1 = 39 + 58 = 97(a) @@: mov [esi], cl ;move character to esi test eax, eax jnz .loop mov eax, 4 ;print the register mov ebx, 1 mov ecx, prt_str mov edx, str_reg_size int 0x80 ret _eoj: ;exit to LINUX mov eax,1 xor ebx,ebx int 0x80 |
|||
![]() |
|
RIxRIpt 31 Jan 2015, 11:38
Quote:
Because you are loading address of register value into eax: `mov eax,reg_ebx` instead of loading register value into eax: `mov eax,[reg_ebx]` And 8 bytes for str_reg must be enough (instead of 32): Code: str_reg 8 dup '0' ;duplicate '0' eight times And please note that old contents of str_reg are not cleared out: Code: test eax, eax ;exists loop as soon as eax is is empty jnz .loop If you don't want a counter, here're some ugly(?) fixes: Code: ;Forcing to loop thru all digits of register: cmp esi, str_reg ;instead of `test eax, eax` ;Or clearing out str_reg before the loop: mov [str_reg + 0], '0000' mov [str_reg + 4], '0000' |
|||
![]() |
|
ed_crumbpacker 31 Jan 2015, 15:20
yeah...I saw that this morning...shouldn't write code and watch hockey at the same time
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.