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 ax, 48
- mov si, ax ; Move our si to start of string
- push 0 ; Push 0 as a marker for stack rewind
- read:
- mov ax, [si] ; Get a letter into ax
- shl ax, 8
- shr ax, 8
- jnz collect ; Check if we hit '\0'
- jmp rewind
- collect:
- push ax ; Push current char onto the stack
- mov ax, si
- add ax, 1
- mov si, ax ; Advance our si pointer
- jmp read
- rewind:
- mov ax, 48
- mov si, ax ; Reload si to start of string
- write:
- pop ax ; Pop off last letter
- shr ax, 8
- mov [si], ax ; Write it into the string
- push ax ; Store it so we can jnz
- mov ax, si
- add ax, 1
- mov si, ax ; Advance si
- pop ax
- jnz write ; Repeat if ax isn't zero
- jmp exit ;
- exit:
- ; We're done
- .data 48
- "Hello world."
Add Comment
Please, Sign In to add comment