Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .rdata
- const10: dd 10
- %define buffer 150
- %define flags buffer
- %define number_buf 0
- section .text
- global print
- print:
- pushad
- sub esp, buffer
- xor edi, edi
- xor esi, esi
- xor ebp, ebp
- xor ecx, ecx
- xor eax, eax
- xor ebx, ebx
- mov ebx, [esp + buffer + 32 + 12]
- mov al, [ebx]
- mov byte[esp + flags], al
- cmp al, '-'
- jne read_symbol
- inc ebx
- read_symbol:
- mov al, [ebx]
- cmp al, 0
- je fin_read
- or al, 20h
- cmp al, 60h
- jg char_to_hex
- jmp num_to_hex
- char_to_hex:
- sub al, 'a' - 10
- jmp put_in_registers
- num_to_hex:
- sub al, '0'
- jmp put_in_registers
- put_in_registers:
- shld edi, esi, 4
- shld esi, ebp, 4
- shld ebp, ecx, 4
- shl ecx, 4
- or cl, al
- inc ebx
- jmp read_symbol
- fin_read:
- xor ebx, ebx
- jmp hex_to_decimal
- hex_to_decimal:
- xor eax, eax
- xor edx, edx
- mov eax, edi
- div dword[const10]
- mov edi, eax
- mov eax, esi
- div dword[const10]
- mov esi, eax
- mov eax, ebp
- div dword[const10]
- mov ebp, eax
- mov eax, ecx
- div dword[const10]
- mov ecx, eax
- add edx, '0'
- mov byte[esp + number_buf + ebx], dl
- inc ebx
- xor edx, edx
- or edx, edi
- or edx, esi
- or edx, ebp
- or edx, ecx
- cmp edx, 0
- jnz hex_to_decimal
- mov ebp, [esp + buffer + 32 + 8]
- xor eax, eax
- xor edi, edi
- xor esi, esi
- jmp get_special_symbol
- get_special_symbol:
- cmp byte[ebp + edi], '-'
- je format_minus
- cmp byte[ebp + edi], '+'
- je format_plus
- cmp byte[ebp + edi], '0'
- je format_zero
- cmp byte[ebp + edi], ' '
- je format_space
- jmp get_width
- format_minus:
- or esi, 1
- inc edi
- jmp get_special_symbol
- format_plus:
- or esi, 2
- inc edi
- jmp get_special_symbol
- format_zero:
- or esi, 4
- inc edi
- jmp get_special_symbol
- format_space:
- or esi, 8
- inc edi
- jmp get_special_symbol
- get_width:
- cmp byte[ebp + edi], 0
- je set_width
- mul dword[const10]
- xor edx, edx
- mov dl, [ebp + edi]
- add eax, edx
- sub eax, 00000030h
- inc edi
- jmp get_width
- set_width:
- cmp ebx, eax
- jge greater_length
- jmp set_output
- greater_length:
- mov eax, ebx
- cmp byte[esp + flags], '-'
- je add_width
- test esi, 2
- jnz add_width
- test esi, 8
- jnz add_width
- jmp set_output
- add_width:
- inc eax
- jmp set_output
- set_output:
- mov edx, [esp + buffer + 32 + 4]
- test esi, 1
- jnz align_left
- test esi, 4
- jnz fill_zeroes
- test esi, 8
- jnz fill_spaces
- test esi, 2
- jnz fill_spaces
- jmp fill_spaces
- align_left:
- jmp align_left_set_sign
- align_left_set_forw_space:
- mov byte[edx], ' '
- inc edx
- dec eax
- cmp eax, 0
- je fin
- jmp align_left_set_next_symb
- align_left_set_sign:
- cmp byte[esp + flags], '-'
- je align_left_set_minus
- test esi, 2
- jnz align_left_set_plus
- test esi, 8
- jnz align_left_set_forw_space
- jmp align_left_set_next_symb
- align_left_set_minus:
- mov byte[edx], '-'
- inc edx
- dec eax
- cmp eax, 0
- je fin
- jmp align_left_set_next_symb
- align_left_set_plus:
- mov byte[edx], '+'
- inc edx
- dec eax
- cmp eax, 0
- je fin
- jmp align_left_set_next_symb
- align_left_set_next_symb:
- cmp ebx, 0
- je align_left_set_space
- jmp align_left_set_number
- align_left_set_space:
- mov byte[edx], ' '
- inc edx
- dec eax
- cmp eax, 0
- je fin
- jmp align_left_set_next_symb
- align_left_set_number:
- mov cl, [esp + number_buf + ebx - 1]
- mov [edx], cl
- inc edx
- dec ebx
- dec eax
- cmp eax, 0
- je fin
- jmp align_left_set_next_symb
- fill_zeroes:
- jmp fill_zeroes_set_sign
- fill_zeroes_set_forw_space:
- mov byte[edx], ' '
- inc edx
- dec eax
- cmp eax, 0
- je fin
- jmp fill_zeroes_set_zero
- fill_zeroes_set_sign:
- cmp byte[esp + flags], '-'
- je fill_zeroes_set_minus
- test esi, 2
- jnz fill_zeroes_set_plus
- test esi, 8
- jnz fill_zeroes_set_forw_space
- jmp fill_zeroes_set_zero
- fill_zeroes_set_minus:
- mov byte[edx], '-'
- inc edx
- dec eax
- cmp eax, 0
- je fin
- jmp fill_zeroes_set_zero
- fill_zeroes_set_plus:
- mov byte[edx], '+'
- inc edx
- dec eax
- cmp eax, 0
- je fin
- jmp fill_zeroes_set_zero
- fill_zeroes_set_zero:
- cmp eax, ebx
- jle fill_zeroes_set_number
- mov byte[edx], '0'
- inc edx
- dec eax
- cmp eax, 0
- je fin
- jmp fill_zeroes_set_zero
- fill_zeroes_set_number:
- mov cl, [esp + number_buf + ebx - 1]
- mov [edx], cl
- inc edx
- dec ebx
- dec eax
- cmp eax, 0
- je fin
- jmp fill_zeroes_set_number
- fill_spaces:
- jmp fill_spaces_set_space
- fill_spaces_set_space:
- cmp eax, ebx
- je fill_spaces_set_sign
- mov byte[edx], ' '
- inc edx
- dec eax
- cmp eax, 0
- je fin
- jmp fill_spaces_set_space
- fill_spaces_set_sign:
- cmp byte[esp + flags], '-'
- je fill_spaces_set_minus
- test esi, 2
- jnz fill_spaces_set_plus
- jmp fill_spaces_set_number
- fill_spaces_set_minus:
- mov byte[edx - 1], '-'
- jmp fill_spaces_set_number
- fill_spaces_set_plus:
- mov byte[edx - 1], '+'
- jmp fill_spaces_set_number
- fill_spaces_set_number:
- mov cl, [esp + number_buf + ebx - 1]
- mov [edx], cl
- inc edx
- dec ebx
- dec eax
- cmp eax, 0
- je fin
- jmp fill_spaces_set_number
- fin:
- mov byte[edx], 0
- add esp, buffer
- popad
- ret
Add Comment
Please, Sign In to add comment