asm babysteps on linux - int 80 std input
Posted: Sun Jun 16, 2013 12:17 pm
Hi,
I'm checkin out asm development (and x86 asm in general) on Linux and while writing this hello world type program I run into a question of how to determine the length for int 80 functions 3 and 4 (especially for 3) when I want to read user input and then write it back to stdout. Also I cant seem to zero out my input variables/lables/memory locations (what is the correct term?) by xoring... And part of the previous input gets strangely printed on next inputs...
Thanks for your help! Hard work on filling the basic knowledge requirements for kernel dev =D
Output:
I'm checkin out asm development (and x86 asm in general) on Linux and while writing this hello world type program I run into a question of how to determine the length for int 80 functions 3 and 4 (especially for 3) when I want to read user input and then write it back to stdout. Also I cant seem to zero out my input variables/lables/memory locations (what is the correct term?) by xoring... And part of the previous input gets strangely printed on next inputs...
Thanks for your help! Hard work on filling the basic knowledge requirements for kernel dev =D
Code: Select all
global _start ;LD linker default entrypoint name
segment .data
welcome_message db "Welcome! Please input some text: ", 0Ah
welcome_length equ $-welcome_message
newline_message db "", 0Ah
newline_length equ $-newline_message
segment .bss
user_input resb 10
user_input_length equ $-user_input
segment .text
_start:
ask:
;print message
mov eax, 4
mov ebx, 1
mov ecx, welcome_message
mov edx, welcome_length
int 80h
call input_string
jmp ask
mov eax, 1
mov ebx, 0
int 80h
input_string:
pusha
;Get user stdin
mov eax, 3
mov ebx, 1
mov ecx, user_input
mov edx, user_input_length ;How to determine this?
int 80h
;Print users input to stdout
mov eax, 4
mov ebx, 1
mov ecx, user_input
mov edx, user_input_length ;How to determine this?
int 80h
;print new line
mov eax, 4
mov ebx, 1
mov ecx, newline_message
mov edx, newline_length
int 80h
;Try to zero out all bits in user input
;since they show up strangely in following inputs
;fails thou
mov eax, user_input ;wrong way to access?
xor eax, eax
popa
ret
Code: Select all
Welcome! Please input some text:
Hello
Hello
Welcome! Please input some text:
Hi
Hi
lo
Welcome! Please input some text: