Linux-SWAT
Forum Addict!
- Joined
- Feb 13, 2010
- Messages
- 9,188
The compare char in a loop, better understood. I hope.
I still don't understand why when the program stops, it's like i've pressed "enter" :
~/devel$ as hello.s -o hello.o ; ld -o hello hello.o ; ./hello
q
~/devel$
~/devel$
Code:
.text
.align 2
.global _start
_start:
ldr r8, =quit_char @ will load the address of quit_char into r8
ldrb r8, [r8] @ load 'q' ascii code (pointed to r8) to r8
mov r2, #1 @ buffer length
mov r7, #3 @ system call number, 3 is 'read'
mov r0, #0 @ file descriptor 0 - stdin
ldr r1, =input @ r1 will point every input in the loop
_loop:
svc 0 @ call the Linux kernel and wait for the input
ldrb r9, [r1] @ load the ascii code of the input (pointed to r1) to r9
cmp r9, r8 @ compare if the input ascii == q ascii
bne _loop @ if not, come back to _loop
mov r7, #1 @ exit
svc 0
.data
input: .byte 0
quit_char: .byte 'q'
~/devel$ as hello.s -o hello.o ; ld -o hello hello.o ; ./hello
q
~/devel$
~/devel$