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 the argument",10,0
- err3: db "inccorect first letter of the argument (should be an upper case letter)",10,0
- err4: db "inccorect second letter of the argument (should be 3 or 5 or 7 or 9)",10,0
- section .bss
- section .text
- len:
- push rbx
- mov rcx,0
- dec rbx
- count:
- inc rcx
- inc rbx
- cmp byte[rbx],0
- jnz count
- dec rcx
- pop rbx
- ret
- display_line:
- enter 0,0
- saveregs
- mov r12, qword [rbp+16] ;; char
- mov r13, qword [rbp+24] ;; q
- mov r14, qword [rbp+32] ;; p
- mov rcx, r13
- cmp r13, 0
- je skip_spaces
- display_spaces:
- mov rax, ' '
- call print_char
- loop display_spaces
- skip_spaces:
- mov rcx, r14
- cmp r14, 0
- je skip_chars
- display_chars:
- mov rax, r12
- call print_char
- loop display_chars
- skip_chars:
- restoregs
- leave
- ret
- display_shape:
- enter 0,0
- saveregs
- mov r15, qword [rbp+24] ;; size
- mov r13, qword [rbp+32] ;; char
- mov rdx, 0
- mov r12, 2
- div r12
- mov r14, rax ;;q
- mov rax, r15
- sub rax, r14
- mov r12, rax ;;p
- mov rcx, r14 ;;q for counter
- mov rbx, r12
- inc rcx
- print_lines:
- push rbx ;;p
- dec rcx
- push rcx ;;q
- push r13 ;;char
- call display_line
- add rsp, 24
- call print_nl
- inc rbx
- inc rcx
- loop print_lines
- restoregs
- leave
- ret
- asm_main:
- ;;Saving regs
- enter 0,0
- saveregs
- ;;Checking number of params
- cmp rdi, qword 2
- jne ERR1
- ;;Checking first param length
- mov rbx, qword [rsi+8]
- call len
- cmp rcx, 2
- jne ERR2
- ;;Checking If first byte is a Upper case letter
- mov rbx, qword [rsi+8]
- cmp byte[rbx], 'A'
- jb ERR3
- cmp byte[rbx], 'Z'
- ja ERR3
- ;;Checking If second byte is a nubmer
- cmp byte[rbx+1], '0'
- jb ERR4
- cmp byte[rbx+1], '9'
- ja ERR4
- ;;Converting from string to integer
- movzx rax, byte[rbx+1]
- sub rax, '0'
- ;;Checking if number is odd
- push rax
- mov rdx, 0
- mov rcx, 2
- div rcx
- cmp rdx, 1
- jne ERR4
- pop rax
- ;;Removing 1 from case of odd numbers
- cmp rax, 1
- je ERR4
- ;;Moving char and digits
- movzx rdx, byte[rbx]
- mov rbx, rax
- ;;Pushing parameters for display_shape
- push rdx
- push rbx
- sub rsp, 8
- call display_shape
- add rsp, 24
- 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
- leave
- ret
Advertisement
Add Comment
Please, Sign In to add comment