I’m trying to learn assembly for various reasons and I’m trying to write a code that says hello bla bla bla
then reads your name, prints your name and says more bla bla bla
but it does not show the text after it gets your name
Im sure its something stupid… sorry…
here is what I have so far:
.section .bss
.lcomm bufname, 256
.section .data
msg1:
.ascii "Hello, please enter your name!\n" # Message to write
len1 = . - msg1 # Length of string
msg2:
.ascii "Good to meet you "
len2 = . - msg2
msg3:
.ascii ". Iam your first assembly program!\n"
len3 = . - msg3
.section .text
.globl _start
_start:
call get_name
get_name:
#should print msg1
mov $4, %eax # system call number (sys_write)
mov $1, %ebx # file descriptor (stdout)
mov $msg1, %ecx # Message to write
mov $len1, %edx # Lenght of message
int $0x80 # Call kernel
#should get user input
mov $3, %eax # System call number (sys_read)
mov $0, %ebx # File descriptor (stdin)
mov $bufname, %ecx # Buffer to store the name
mov $256, %edx # Lenght of buffer
int $0x80
#should print msg2
mov $4, %eax
mov $1, %ebx
mov $msg2, %ecx
mov $len2, %edx
int $0x80
#should print bufname (doesn't)
mov $bufname, %ecx
mov $256, %edx
int $0x80
#should print msg3 (doesn't)
mov $msg3, %ecx
mov $len3, %edx
int $0x80
call exit
exit:
mov $1, %eax
mov $0, %ebx
int $0x80
To compile i use
as Jes.s -o Jes.o
ld Jes.o -o Jes
This is the output i get
$ ./Jes
Hello, please enter your name!
renato
Good to meet you
It should show
Good to meet you renato. Iam your first assembly program!
Why is this wrong?
and much thanks for your time!
The problem is that when you call the interrupt (
int) the registers can get overwritten. It’s not like making a function call where the registers are saved and restored for you. You need to place duplicates of these lines before all of yourintcalls: