Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %include "simple_io.inc"
- global asm_main
- SECTION .data
- err1: db "incorrect number of command line arguments",10,0
- err2: db "incorrect length of argument",10,0
- err3: db "incorrect first letter of argument (should be 3 or 5 or 7 or 9)",10,0
- err4: db "incorrect second letter of argument (should be an upper case letter)", 10,0
- sizeparam: db "size is: ", 10, 0
- letterparam: db "letter is: ", 10,0
- SECTION .bss
- SECTION .text
- ;recieves parameters: letter in [RBP+24], number in [RBP+32]
- display_shape:
- enter 0, 0
- saveregs
- mov rax, sizeparam
- call print_string
- mov rax, [RBP+32]
- call print_int
- call print_nl
- mov rax, letterparam
- call print_string
- mov rax, [rbp+24]
- call print_char
- call print_nl
- restoregs
- leave
- ret
- asm_main:
- enter 0,0 ; setup routine
- saveregs ; save all registers
- ;; the first param is in rdi, so rdi=argc
- cmp rdi, qword 2 ; argc should be 2
- jne ERR1
- ;; check length here
- mov rbx, qword 0
- mov rbx, [rsi+8]
- mov al, byte [rbx+2]
- cmp al, byte 0
- jne ERR2
- ;; check if first char is a digit
- mov r12, qword 0
- mov r12b, byte [rbx]
- cmp r12, 48 ; compare al to the ASCII value of '1'
- jb ERR3 ; error if ASCII value is less than '1' = 31h
- cmp r12, 57 ; compare al to the ASCII value of '9'
- ja ERR3
- ;; must be above one and odd
- sub r12, 48 ;convert char to number
- cmp r12, 3
- jl ERR3 ; can't be less than 3
- cmp r12, 4 ; cant be even
- je ERR3
- cmp r12, 6 ; cant be even
- je ERR3
- cmp r12, 8 ; cant be even
- je ERR3
- ;; second char must be upper case letter
- mov r11, qword 0
- mov r11b, byte [rbx+1] ;contains the second char
- ;; checks if second char is upper case letter
- cmp r11, 65
- jb ERR4
- cmp r11, 90
- ja ERR4
- push r12
- push r11
- sub rsp, 8
- call display_shape
- add rsp, 8
- pop r11
- pop r12
- jmp asm_main_end
- ERR1:
- mov rax, err1
- call print_string
- jmp asm_main_end
- ERR2:
- mov rax, err2
- call print_string
- jmp asm_main_end
- ERR3:
- mov rax, err3
- call print_string
- jmp asm_main_end
- ERR4:
- mov rax, err4
- call print_string
- jmp asm_main_end
- asm_main_end:
- restoregs ; restore all registers
- leave
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement