rendered paste body# comments start with # in column 1
# commands which start with a . (dot) are assembler directives
# which do not generate machine code
.intel_syntax noprefix
.global _main
# put external (system) calls here
.extern _exit
.extern _getchar
.extern _putchar
.data
# declare variables here
welcome1: .string "[= Press the letter corrisponding to the option... =]"
splitter: .string "[-----------------------------------------------------------]"
optiona: .string "[- Option a - enter a string into buffer. -]"
optionb: .string "[- Option b - display string to the screen. -]"
optionc: .string "[- Option c - encode/decode string using rot13 algorithm. -]"
optiond: .string "[- Option d - program exits. -]"
author: .string "[= Author: Anthony Paimany |:| 06037852 |:| 1/2/07 -]"
not1: .string "[- Enter String to be loaded into buffer -]"
not2: .string "[- String loaded into buffer -]"
not3: .string "[- Printing out buffer -]"
choice: .rept 1
.byte 0
.endr
buffer: .rept 80 # reserve 80 bytes in memory
.byte 0
.endr
.text
_main:
lea ebx, splitter
call wrstring
call newline
lea ebx, welcome1
call wrstring
call newline
lea ebx, splitter
call wrstring
call newline
lea ebx, optiona
call wrstring
call newline
lea ebx, optionb
call wrstring
call newline
lea ebx, optionc
call wrstring
call newline
lea ebx, optiond
call wrstring
call newline
lea ebx, splitter
call wrstring
call newline
lea ebx, author
call wrstring
call newline
lea ebx, splitter
call wrstring
call newline
jmp getoption
# programs always end with ...
exit:
mov eax, 0
call _exit
# user-defined subroutines(methods) go here ...
getoption:
lea ebx, choice
call getstring
mov al, choice
cmp al, 0x61
je option1
cmp al, 0x62
je option2
cmp al, 0x63
je option3
cmp al, 0x64
je option4
jmp exit
option1:
lea ebx, not1
call wrstring
call newline
lea ebx, buffer
call getstring
lea ebx, not2
call wrstring
call newline
lea ebx, buffer
call wrstring
call newline
jmp getoption
option2:
lea ebx, not3
call wrstring
call newline
lea ebx, buffer
call wrstring
call newline
jmp getoption
option3:
option4:
jmp exit
#subroutine for writting strings
wrstring: # ebx contains string pointed to
mov al, [ebx] # get character
wh1:
cmp al, 0
je whe1 # jump if al == 0
whd1:
push ebx
push eax
call _putchar # display on screen
add esp, 4
pop ebx
inc ebx # ebx points to next char
mov al, [ebx] # get character
jmp wh1
whe1:
ret
newline:
mov al, 10
push eax
call _putchar
add esp,4
ret
getstring:
push ebx
call _getchar # input char
# char returned in al
pop ebx
wh2:
cmp al, 0x0a # while not LF do
je end1 #
whd2:
movb [ebx], al # note movb (see note)
inc ebx
push ebx # point to next location
call _getchar # input char
# char returned in al
pop ebx
jmp wh2
end1:
movb [ebx], 0 # make string null terminated, movb again
ret
rot13:
# ls byte of edx contains value to be en/decoded
# if char >= 0x41 && char <= 0x5a then uppercase
# if (char+13) > 0x5a then subtract 26
# if char >= 0x61 && char <= 0x7a then lowercase
# if (char+13) > 0x7a then subtract 26
#
cmpb dl, 0x41
jl r13l2
cmpb dl, 0x5a
ja r13l2
# uppercase
addb dl, 13
cmpb dl, 0x5a
jle r13l1
subb dl, 26
r13l1: jmp r13le
r13l2: cmpb dl, 0x61
jl r13le
cmpb dl, 0x7a
ja r13le
# lowercase
addb dl, 13
cmpb dl, 0x7a
jbe r13le # b not l, ignore sign bit!
subb dl, 26
r13le: ret
# end of program