Created
October 25, 2018 07:24
-
-
Save EdoardoVignati/aa91ec281cac37d26f058bbd8812d846 to your computer and use it in GitHub Desktop.
Read from stdin and print input - AT&T assembly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################# | |
# How to run # | |
################# | |
# $ as --gstabs read.s -o read.o | |
# $ ld read.o -o read | |
# $ ./read | |
################ | |
.text | |
.globl _start | |
MAX_CHAR=30 | |
_start: | |
## Start message ## | |
movl $4, %eax | |
movl $1, %ebx | |
movl $msg, %ecx | |
movl $len, %edx | |
int $0x80 | |
## READ ## | |
movl $3, %eax #sys_read (number 3) | |
movl $0, %ebx #stdin (number 0) | |
movl %esp, %ecx #starting point | |
movl $MAX_CHAR, %edx #max input | |
int $0x80 #call | |
## Need the cycle to count input length ## | |
movl $1, %ecx #counter | |
end_input: | |
xor %ebx, %ebx | |
movb (%esp), %bl | |
add $1, %esp #get next char to compare | |
add $1, %ecx #counter+=1 | |
cmp $0xa, %ebx #compare with "\n" | |
jne end_input #if not, continue | |
## WRITE ## | |
sub %ecx, %esp #start from the first input char | |
movl $4, %eax #sys_write (number 4) | |
movl $1, %ebx #stdout (number 1) | |
movl %ecx, %edx #start pointer | |
movl %esp, %ecx #length | |
int $0x80 #call | |
## EXIT ## | |
movl $1, %eax | |
int $0x80 | |
.data | |
msg: .ascii "Insert an input:\n" | |
len =.-msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
xor usding for what ?