98 lines
1.9 KiB
NASM
98 lines
1.9 KiB
NASM
|
|
format ELF
|
|
|
|
|
|
;==============================
|
|
;public argc as '__argc' - no needed for tiny app
|
|
public num2cell_num as 'num2cell_num'
|
|
public cell_num2num as 'cell_num2num'
|
|
public cell_num_chars as 'cell_num_chars'
|
|
|
|
section '.text'
|
|
|
|
; IN: arg0 = num
|
|
; arg1 - ptr buffer(12 chars)
|
|
; OUT: -
|
|
num2cell_num:
|
|
; 26 = 11010b = Z
|
|
; AA = 27 = 11011b
|
|
;
|
|
; dec: 11010b = AA
|
|
; 11010b*26 = 1010100100b = AAA
|
|
; X2 = 10101001000b = ABA
|
|
; X3 = 11111101100b = ACA
|
|
; X4 = 101010010000b = ADA
|
|
; = 110100110100b = AEA
|
|
;
|
|
; ;dec num
|
|
;.loop:
|
|
;
|
|
; ; copy stack in buffer
|
|
;
|
|
push ebx edi ebp
|
|
mov ebp, esp
|
|
|
|
mov eax, dword [esp + 4*3 + 4]
|
|
dec eax
|
|
.cycle:
|
|
xor ecx, ecx
|
|
mov edx, 1 shl 27
|
|
mov ebx, 26 shl 27
|
|
|
|
.shift:
|
|
cmp eax, ebx
|
|
jb @F
|
|
sub eax, ebx
|
|
or ecx, edx
|
|
@@:
|
|
shr ebx, 1
|
|
shr edx, 1
|
|
jnz .shift
|
|
|
|
add al,'A'
|
|
dec esp
|
|
mov byte [esp],al
|
|
|
|
mov eax,ecx
|
|
test eax,eax
|
|
lea eax,[eax-1]
|
|
jnz .cycle
|
|
|
|
mov edi, [ebp + 4*3 + 8]
|
|
@@:
|
|
cmp esp, ebp
|
|
je @f
|
|
|
|
mov al, byte[esp]
|
|
stosb
|
|
inc esp
|
|
jmp @b
|
|
@@:
|
|
xor eax, eax
|
|
stosb
|
|
pop ebp edi ebx
|
|
ret 8
|
|
|
|
; IN: arg0 = ptr to string of number
|
|
; OUT: eax - number or null
|
|
cell_num2num:
|
|
|
|
.loop:
|
|
|
|
;cmp , 0
|
|
;jne .loop
|
|
;inc old
|
|
; mul 26
|
|
|
|
ret 4
|
|
|
|
; AA = (1*26 + 0 ) + 1 -1
|
|
|
|
; AAA =
|
|
; A = 1
|
|
|
|
;section '.data'
|
|
; dec 01234567890123456789012345
|
|
; 12345678901234567890123456
|
|
cell_num_chars: db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
.size = $ - cell_num_chars |