Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Reverse a null-terminated string in-place
- ; using the stack.
- .text 0
- mov si, 32 ; Move our si to start of string
- push 0 ; Push 0 as a marker for stack rewind
- read:
- mov acc, [si] ; Get a letter into acc
- jnz collect ; Check if we hit '\0'
- jmp rewind
- collect:
- push acc ; Push current char onto the stack
- add si, 1 ; Advance our si pointer
- jmp read
- rewind:
- mov si, 32 ; Reload si to start of string
- write:
- pop acc ; Pop off last letter
- mov [si], acc ; Write it into the string
- add si, 1 ; Advance si
- jnz write ; Repeat if acc isn't zero
- jmp exit ;
- exit:
- ; We're done
- .data 32
- "Hello world."
Add Comment
Please, Sign In to add comment