Created
February 5, 2014 03:12
-
-
Save rackerbenoit/8816882 to your computer and use it in GitHub Desktop.
This file contains 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
# | |
# An x86-32 assembly program that echos one character | |
# | |
# declare external functions | |
.extern getchar # get one character from the console | |
.extern putchar # write one character to the console | |
# declare main as global | |
.global main | |
# the main program | |
main: | |
call getchar #Put first character onto %eax | |
cmp $-1, %eax # Is the loop still supposed to run? | |
je exit #Exit if the loop is no longer true | |
push %eax | |
jmp compare #Start comparing the values | |
output: | |
call putchar #Output onto terminal | |
add $4, %esp #pop the stack | |
jmp main | |
exit: | |
mov $0, %eax #reset value and end program | |
ret | |
compare: | |
cmpl $'p', (%esp) | |
je toupper | |
cmpl $'a', (%esp) | |
je toupper | |
cmpl $'u', (%esp) | |
je toupper | |
cmpl $'l', (%esp) | |
je toupper | |
cmpl $'b', (%esp) | |
je toupper | |
cmpl $'e', (%esp) | |
je toupper | |
cmpl $'n', (%esp) | |
je toupper | |
cmpl $'o', (%esp) | |
je toupper | |
cmpl $'P', (%esp) | |
je tolower | |
cmpl $'A', (%esp) | |
je tolower | |
cmpl $'U', (%esp) | |
je tolower | |
cmpl $'L', (%esp) | |
je tolower | |
cmpl $'B', (%esp) | |
je tolower | |
cmpl $'E', (%esp) | |
je tolower | |
cmpl $'N', (%esp) | |
je tolower | |
cmpl $'O', (%esp) | |
je tolower | |
jmp output | |
tolower: | |
add $32, (%esp) | |
jmp output | |
toupper: | |
sub $32, (%esp) | |
jmp output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment