- #1
twoski
- 181
- 2
Homework Statement
I have to write a simple program in NASM to read in a character then output what kind of character it is.
The Attempt at a Solution
There are some things about NASM that confuse me so i marked them.
Code:
segment .data
BUFFLEN equ 1 ; length of buffer
CtrlMsg db "Control Character", 10 ;what does this 10 do?
SymbolMsg db "Symbol", 10
NumberMsg db "Number", 10
CapitalMsg db "Capital Letter", 10
LowercaseMsg db "Lower Case Letter", 10
segment .bss
input resb 1 ; characters are 1 byte
segment .text
global _start
_start: ; main function
mov eax, 3
mov ebx, 1
mov ecx, input
mov edx, BUFFLEN
int 0x80 ; interrupt and get user input
cmp byte [ecx],20h ; go through the ascii table ranges
jb IsControl
cmp byte [ecx],30h
jb IsSymbol
cmp byte [ecx],3Ah
jb IsNumber
cmp byte [ecx],41h
jb IsSymbol
cmp byte [ecx],5Bh
jb IsCapital
cmp byte [ecx],61h
jb IsSymbol
cmp byte [ecx],7Bh
jb IsLowercase
cmp byte [ecx],7Fh
je IsControl
jmp IsSymbol ; for anything else, assume it's a symbol
IsLowercase:
mov edx, len ; how do you get the length of a string in nasm?
mov ecx, LowercaseMsg
jmp Print
IsCapital:
mov edx, len
mov ecx, CapitalMsg
jmp Print
IsSymbol:
mov edx, len
mov ecx, SymbolMsg
jmp Print
IsNumber:
mov edx, len
mov ecx, NumberMsg
jmp Print
IsControl:
mov edx, len
mov ecx, CtrlMsg
jmp Print
Print:
mov ebx, 1 ; writing to screen
mov eax, 4 ; sysout command
int 0x80 ; interrupt
exit:
mov eax, 1 ; Select system call 1
xor ebx, ebx ; Set default exit code
int 0x80 ; Invoke selected system call