section .text global _start _start: pop rax ; get number of args pop rbx ; get program name cmp rax,3 ; make sure there are 2 arguments (+1 for program name) jne _bad ; if not, jump to error message pop rdx ; first argument pop rcx ; second argument call _length_entry mov [stra],rcx call _atoi_entry call _text_entry call _exit _output: mov rax,1 mov rdi,1 mov rsi,[stra] ; move pointer of the string start into rsi mov rdx,[strLen] ; length of str into rdx syscall ; kernel halp _newline: mov rax,1 mov rdi,1 mov rsi,ten mov rdx,1 syscall ret _exit: mov rax,60 ; exit xor rdi,rdi ; don't error syscall ; peace out _bad: mov qword [stra],feelbad ; write feelbad to output string mov qword [strLen],feelLen ; write feelLen to output string length call _output jmp _exit _length_entry: mov qword [strLen],0 ; zero string length jmp _length_test _length: inc qword [strLen] ; increment string length inc rcx ; string pointer to next character _length_test: cmp byte [rcx],0 ; check if null character jne _length sub rcx,[strLen] ; set rcx back to beginning of string ret ; if null byte, ret _atoi_entry: xor r9,r9 ; zero accumulator mov [asciinum],rdx ; write string pointer to [asciinum] _atoi: xor rax,rax ; set rax to 0 mov r10,[asciinum] ; pointer to asciinum in r10 mov al,[r10] ; first byte of string into first byte of al cmp al,0 ; make sure we haven't hit end of string je _atoi_exit lea r11,[r9*8] lea r9,[r11+r9*2] ; multiply r9 by 10 sub al,48 ; ascii -> digits cmp al,9 ; make sure they're numbers 0-9 ja _bad add r9,rax ; incriment accumulator inc qword [asciinum] ; shift pointer to string up by 1 (next character) jmp _atoi _atoi_exit: mov [asciiInt],r9 ; write accumulator to asciiInt ret _text_entry: xor r12,r12 ; zero a counter jmp _text_mult_cmp _text_mult: ; text_mult is effectively a while loop that prints our ; string r9 times, since r9 is our accumulator from before call _output inc r12 _text_mult_cmp: cmp r12,r9 je _exit jmp _text_mult section .data stra dq 0 ; reserve space for string pointer strLen dq 0 ; reserve some space for length asciinum dq 0 asciiInt dq 0 ten db 10 ; sigh. set the value of ten to be 10 feelbad db 'Your args are bad and you should feel bad. Proper syntax: args ' feelLen equ $-feelbad ; set length of feelbad to feelLen