I'm having trouble understanding how to traverse a 2-d array in x86 assembly language. I am missing a bit of understanding. This is what I have so far.
The issue is the lines with //offset and //moving through array
For the //offset line the error I am getting is "non constant expression in second operand"
and also
"ebx: illegal register in second operand"
For the next line I get the error
"edx: illegal register in second operand"
mov esi, dim
mul esi
mov eax, 0 // row index
mov ebx, 0 // column index
mov ecx, dim
StartFor:
cmp ecx, esi
jge EndFor
lea edi, image;
mov edx, [eax *dim + ebx] // offset
mov dl, byte ptr [edi + esi*edx] // moving through array
mov edx, edi
and edx, 0x80
cmp edx, 0x00
jne OverThreshold
mov edx, 0xFF
OverThreshold:
mov edx, 0x0
See x86 tag wiki, including the list of addressing modes.
You can scale an index register by a constant, but you can't multiply two registers in an addressing mode. You'll have to do that yourself (e.g. with imul edx, esi, if the number of columns isn't a compile time constant. If it's a power-of-2 constant, you can shift, or even use a scaled addressing mode like [reg + reg*8]).
re: edit: *dim should work if dim is defined with something like dim equ 8. If it's a memory location holding a value, then of course it's not going to work. The scale factor can be 1, 2, 4, or 8. (The machine code format has room for a 2-bit shift count, which is why the options are limited.)
I'd also recommend loading with movzx to zero-extend a byte into edx, instead of only writing dl (the low byte). Actually nvm, your code doesn't need that. In fact, you overwrite the value you loaded with edi. I assume that's a bug.
You can replace
imul edx, esi
mov dl, byte ptr [edi + edx] ; note the different addressing mode
mov edx, edi ; bug? throw away the value you just loaded
and edx, 0x80 ; AND already sets flags according to the result
cmp edx, 0x00 ; so this is redundant
jne OverThreshold
with
imul edx, esi
test 0x80, byte ptr [edi + edx] ; AND, discard the result and set flags.
jnz
Of course, instead of multiplying inside the inner loop, you can just add the columns in the outer loop. This is called Strength Reduction. So you do p+=1 along each row, and p+=cols to go from row to row. Or if you don't need to care about rows and columns, you can just iterate over the flat memory of the 2D array.
A 2-dimensional array is just an interpretation of a sequence of bytes. You'll have to choose in which order to store the items. For example, you might choose "row-major order".
I've written a demo where a buffer is filled with a sequence of numbers. Then the sequence is interpreted as single- and two-dimensional array.
tx86.s
%define ITEM_SIZE 4
extern printf
section .bss
cols: equ 3
rows: equ 4
buf: resd cols * rows
c: resd 1
r: resd 1
section .data
fmt: db "%-4d", 0 ; fmt string, '0'
fmt_nl: db 10, 0 ; "\n", '0'
section .text ; Code section.
global main
main:
push ebp
mov ebp, esp
; fill buf
mov ecx, cols * rows - 1
mov [buf + ITEM_SIZE], ecx
.fill_buf:
mov [buf + ecx * ITEM_SIZE], ecx
dec ecx
jnz .fill_buf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; buf as 1-dimensional array
; buf[c] = [buf + c * ITEM_SIZE]
xor ecx, ecx
mov [c], ecx
.lp1d:
mov ecx, [c]
push dword [buf + ecx * ITEM_SIZE]
push dword fmt
call printf
mov ecx, [c]
inc ecx
mov [c], ecx
cmp ecx, cols * rows
jl .lp1d
; print new line
push dword fmt_nl
call printf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; buf as 2-dimensional array
; buf[r][c] = [buf + (r * cols + c) * ITEM_SIZE]
xor ecx, ecx
mov [r], ecx
.lp1:
xor ecx, ecx
mov [c], ecx
.lp2:
; calculate address
mov eax, [r]
mov edx, cols
mul edx ; eax = r * cols
add eax, [c] ; eax = r * cols + c
; print buf[r][c]
push dword [buf + eax * ITEM_SIZE]
push dword fmt
call printf
; next column
mov ecx, [c]
inc ecx
mov [c], ecx
cmp ecx, cols
jl .lp2
; print new line
push dword fmt_nl
call printf
; next row
mov ecx, [r]
inc ecx
mov [r], ecx
cmp ecx, rows
jl .lp1
mov esp, ebp
pop ebp ; restore stack
xor eax, eax ; normal exit code
ret
Buidling(on Linux)
nasm -f elf32 -l tx86.lst tx86.s
gcc -Wall -g -O0 -m32 -o tx86 tx86.o
Running
./tx86
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2
3 4 5
6 7 8
9 10 11
Related
Today I'm working on arrays and addressing modes so I made this snippet to train myself. Everything is working fine (apparently) but I chose the easiest way using fixed size arrays. My question is about dynamic memory allocation. In my code, my arrays arrayand array2 have a fixed size (8 * 4(int)). If I wanted to extend them, or to speak with C concepts, make a realloc or something like depending on real time values for the size, may I have to implement system calls like sys_brk and mmapby myself in assembly
or is there an other option ? The other question deals with the part of my code used to reverse an array (label .reversing) I know they are faster solutions than mine so if you could give me some advices, it would be nice.
%define ARRAY_LEN 8
%macro print 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 0x80
%endmacro
%macro exit 0
xor ebx, ebx
mov eax, 1
int 0x80
%endmacro
section .bss
sumarrays resd 1
dynarray resd 256
section .rodata
highest equ 0x78
evensum equ 0x102
sumarray1 equ 0x1e6
sumarray2 equ 0x256
section .data
revarray times ARRAY_LEN dd 0
strok db "Good result !", 0xa, 0
lenstrok equ $ - strok
strerror db "Bad result !", 0xa, 0
lenerror equ $ - strerror
array dd 0x33, 0x21, 0x32, 0x78, 0x48, 0x77, 0x19, 0x10
array2 dd 0x12, 0x98, 0x65, 0x62, 0x4e, 0x3e, 0x1f, 0x3a
section .text
global sort
global sum
global _start
_start:
; sort array from highest value to lowest value
sub esp, 8
push ARRAY_LEN
push array
call sort
add esp, 8
and esp, 0xfffffff0
; copying array into some another ones : array -> revarray
mov esi, eax
mov edi, revarray
mov ecx, ARRAY_LEN
rep movsd
; now let's reverse the array
mov esi, revarray ;esi = address of array
mov ecx, ARRAY_LEN ;ecx = number of elements
lea edi, [esi + ecx * 4 - 4]
.reversing:
mov eax, [esi] ;eax = value at start
mov ebx, [edi] ;ebx = value at end
mov [edi], eax
mov [esi], ebx
add esi, 4 ;incrementing address of next item at start
sub edi, 4 ;incrementing address of next item at end
cmp esi, edi ;middle reached ?
jb .reversing ;no we continue
.reversed:
;after, we compute the sum of the elements in the array
mov esi, revarray ; address of array
mov edx, ARRAY_LEN ; num elem of array
sub esp, 8
call arraysum ; sum computation
add esp, 8
cmp eax, sumarray1 ; we check the result to be sure
jne .failure
; merging array2 with array
; esi = source address of first array
; edi = address of second array, the destination one
mov esi, array2
mov edi, array
sub esp, 8
call mergearrays
add esp, 8
; we compute the sum of the merged arrays into the new (old one in fact)
mov esi, array
mov ecx, ARRAY_LEN
add esp, 8
call arraysum
add esp, 8
cmp eax, 0x43c ; we check the result to be sure
jne .failure ; if not egal, exit
; compute the sum of even numbers only in the array
; set up edx to 0 at beginning of loop
; cmova edx, $value_even_number
mov esi, revarray
xor ebx, ebx
xor ecx, ecx
.iterate:
xor edx, edx ; setting up edx to 0
mov eax, [esi + ecx * 4]
test al, 1 ; CF == 0 ? so it's an even number
cmovz edx, eax ; we store the value of current element in edx
add ebx, edx ; so in case of odd number => add 0
inc ecx
cmp ecx, ARRAY_LEN ; end of array reached ?
jne .iterate ; no, we continue
cmp ebx, 0x102 ; check if result is good
je .success
jmp .failure
exit
.success:
print strok, lenstrok
exit
.failure:
print strerror, lenerror
exit
; ********************************************
; computes the sum of all elements of an array
; esi = address of the array
; edx = number of elements in array
; output : eax
; ********************************************
arraysum:
push ebx
xor ebx, ebx
xor ecx, ecx
.arraysum:
mov eax, [esi + ecx *4]
add ebx, eax
inc ecx
cmp ecx, edx
je .sumdone
jmp .arraysum
.sumdone:
mov eax, ebx
pop ebx
ret
; *********************************************
; procedure that sort array from highest to lowest value
; first arg = address of the array
; second arg = number of elements in a array
; return : eax, sorted array
; ********************************************
sort:
push ebp
mov ebp, esp
mov edx, [ebp + 12]
.loop1:
mov esi, [ebp + 8]
mov ecx, [ebp + 12]
.loop2:
mov eax, [esi]
mov ebx, [esi + 4]
cmp eax, ebx
jg .skip
mov [esi], ebx
mov [esi + 4], eax
.skip:
add esi, 4 ;perform loop checks
dec ecx
cmp ecx, 1
ja .loop2
dec edx
ja .loop1
mov eax,[ebp + 8] ; save result in eax
mov esp,ebp
pop ebp
ret
; ****************************************************
; function adding two arrays merging them
; esi = address of first array
; edi = address of second array (destination array)
; ****************************************************
mergearrays:
xor ecx, ecx
.merging:
mov eax, [esi + ecx * 4]
xadd [edi + ecx * 4], eax
inc ecx
cmp ecx, ARRAY_LEN
je .mergedone
jmp .merging
.mergedone:
ret
I defined a DWORD variable: arr DWORD 6 Dup(?) and tried to view this array with visual studio debugger.
I did try arr, 6 but it doesn't seem to work while debugging assembly code.
I also tried arr, arr + 1, arr + 2 separately but the result is terribly wrong.
How to view the entire array?
ReadDec_inline proc Uses eax ebx ecx esi edi, n:DWORD, pArr:DWORD
Local OldEsp:DWORD
; Type in n numbers
mov eax,10
mov ebx,n
mul ebx
add eax,n
sub eax,1; add (n-1) space characters
mov OldEsp,esp
sub esp,eax
mov esi,esp
invoke ReadString,esi,45,offset _dword
;Now we extract
mov esi,pArr
mov ecx,n
L1:
mov eax,0
W1:
.If(BYTE PTR[esp + eax] == " " || BYTE PTR[esp + eax] == 0)
mov BYTE PTR[esp+eax],0
jmp quitW1
.Else
inc eax
.EndIf
jmp W1
quitW1:
mov edi,esp
mov ebx,eax
invoke ReadDec, edi, 1
mov [esi],eax ; Fetch the number
add esi,4
add esp,ebx
inc esp ; Next number
loop L1
mov esp,OldEsp
ret
ReadDec_inline endp
proc Uses eax ebx ecx esi edi
Because of the mul ebx instruction, you should add EDX to the list. The result of this multiplication will be in EDX:EAX.
Or better, change
mov eax,10
mov ebx,n
mul ebx
add eax,n
sub eax,1; add (n-1) space characters
into
imul eax, n, 10 + 1
dec eax
invoke ReadString,esi,45,offset _dword
Shouldn't this hardcoded 45 be actually 65? Same as the calculated value?
Your L1 loop depends on the ECX register. I don't think that ECX is a call-preserved register, so probably invoke ReadDec, edi, 1 messes up the count.
mov esi, pArr
mov ecx, n
L1:
mov edi, esp
push ecx ; (1)
xor ebx, ebx
W1:
.If(BYTE PTR[edi + ebx] == " " || BYTE PTR[edi + ebx] == 0)
mov BYTE PTR[edi + ebx], 0
jmp quitW1
.Else
inc ebx
.EndIf
jmp W1
quitW1:
invoke ReadDec, edi, 1
mov [esi], eax ; Fetch the number
add esi, 4
pop ecx ; (1)
add esp, ebx
inc esp ; Next number
dec ecx
jnz L1
I defined a DWORD variable: arr DWORD 6 Dup(?) and tried to view this array with visual studio debugger.
Your invoke ReadDec_inline, 3, offset arr asks for just 3 array elements and you can see their values in the Memory 1 pane. I sincerely thought the issue here was not having specified the whole 6.
However, it fails in the Watch 1 pane because Visual Studio allows you to write expressions in the Watch windows. This means that arr, arr+1, arr+2, and arr+4 are expressions that first retrieve the value at arr (the first array element which has the value 13), and then have some constant added.
I don't use Visual Studio myself, but for MASM you could try:
arr[0] or just arr
arr[4]
arr[8]
or
[arr+0] or just arr
[arr+4]
[arr+8]
I am trying to write a program that gets a number with one or two digits and write Hello! as many times as that number.
I used this posts to write my code:
NASM: The loop turns into an infinite loop
Check null character in assembly language
Multi-Digit Input from NASM I did not understand this :)
But my code only works for two digit numbers and the result for single digit numbers are wrong.
My code:
section .data
msg db 'Hello!',0xA
len equ $-msg
section .bss
n resb 2
section .text
global _start
_start:
;get n
mov edx, 2
mov ecx, n
mov ebx, 0
mov eax, 3
int 0x80
lea esi,[n] ;address of our text
call toint
;loop for print 'Hello!\n'
print_loop:
push ecx
mov edx, len
mov ecx, msg
mov ebx, 1
mov eax, 4
int 0x80
pop ecx
loop print_loop
mov eax, 1
int 0x80
toint:
push eax
push ebx
xor ebx, ebx
next_digit:
movzx eax, byte[esi]
sub al , '0'
imul ebx, 10
add ebx, eax
inc esi
cmp byte [esi] , 0x0 ;check next character is null or not
jne next_digit
; end_loop:
mov ecx, ebx
pop eax
pop ebx
ret
The sys_read call returns in EAX the count of characters that were sent to your inputbuffer. Because you allowed for an input of max. 2 characters, this count will be either 0, 1, or 2. You could use this info in your toint routine.
; IN (eax,esi) OUT (ecx)
toint:
mov ecx, eax ; Number of digits
jecxz done
push eax ; (1)
push ebx ; (2)
push esi ; (3)
xor ebx, ebx
next:
movzx eax, byte [esi]
sub al , '0'
imul ebx, 10
add ebx, eax
inc esi
dec ecx
jnz next
mov ecx, ebx
pop esi ; (3)
pop ebx ; (2)
pop eax ; (1)
done:
ret
Please notice that there's a reversed ordering to be observed when preserving/restoring registers on the stack! (Your code missed this...)
4 tips
a. Prefer the MOV variant to load an address. It's always a shorter instruction.
b. Guard yourself against an input of zero.
c. Don't use LOOP. It's a slow instruction.
d. Provide the exit code to terminate the program.
mov esi, n ; (a)
call toint ; -> ECX
jecxz Exit ; (b)
print_loop:
...
dec ecx ; (c)
jnz print_loop
Exit:
xor ebx, ebx ; (d)
mov eax, 1
int 0x80
I asked for help earlier and thought I was home free but I'm not. My logic was wrong and I've greatly altered it. This program is supposed to return the Max int in the array (which also happens to be the last element). After tracing it with GDB a few times, I see that I get to the 5th (2nd to last) element in the array, "20", when I hit a segmentation fault and the program halts. I set ECX to the array length and subtracted 1 from ECX to avoid this, but my logic is obviously wrong. Am I wrong in depending on the ECX counter to terminate the loop. Any ideas please?
***EDIT MAJOR EDITS TO CODE
SECTION .data ;data section
msg1: db "Here are the array elements:", 10, 0
msg1Len: equ $-msg1
msg2: db "Here is the sorted array:", 10, 0
msg2Len: equ $-msg2
arr: dd 12, 16, 6, 18, 10, 40, 30
arrLen: equ ($-arr)/4 ;number of elements = array length / 4
SECTION .bss
max resd 1 ;declare and reserve space for max
SECTION .text
global bsort
bsort:
push ebp ; save old ebp register
mov ebp, esp ; build a new stack
restart:
mov ebx, arr ; the base address argument is saved in ebx register
mov ecx, arrLen ; the size argument is saved in exc register
sub ecx, 1 ; Last member has no following element to compare with.
; So we need to reduce the counter by 1
top:
mov eax, [ebx] ;; access first array element. Move its value to eax
cmp eax, [ebx+4] ; compare the value of eax ([ebx]) with [ebx+4]
jle noswap ; if value at eax is less or equal to value of [ebx+4]
; no need to exchang values. Jump to noswap
xchg eax, [ebx+4] ; if value at eax > value [ebx+4], exchange
mov [ebx], eax ; store the new exchanged value at [ebx]
jmp restart ; reset the base address and counter. Start over
noswap:
add ebx, 4 ; move to the next array element
loop top ; loop back to the top if the register ecx > 0
leave
ret
global main
main:
push ebp
mov ebp, esp
mov ecx, msg1 ;print msg1
mov edx, msg1Len
call PString
;save array base address in ebx and save sizein in ecx
mov ebx, arr
mov ecx, arrLen; store num elements in ecx
;loop to print array
PrintArray:
mov eax, [ebx] ;move value [ebx] to eax
call PrintDec
call Println
add ebx, 4
loop PrintArray
;call bubblesort
call bsort
mov ecx, msg2
mov edx, msg2Len
call PString
;save arr base add in sbx and size in ecx
mov ebx, arr
mov ecx, arrLen
PrintSortedArray:
mov eax, [ebx]
call PrintDec
call Println
add ebx, 4
loop PrintSortedArray
;exit program and clean stack
mov esp, ebp
pop ebp
ret
PString:; save register values of the called function
pusha
mov eax,4 ; use 'write' system call = 4
mov ebx,1 ; file descriptor 1 = STDOUT
int 80h ; call the kernel
; restore the old register values of the called function
popa
ret
Println:
;will call PString func
;will change content of ecx and edx
;need to save registers used by the main program
section .data
nl db 10
section .text
pusha
mov ecx, nl
mov edx, 1
call PString
;return original register values
popa
ret
PrintDec:
;saves all registers so they return unmodified
;build the function to handle dword size
section .bss
decstr resb 10 ; 10 32-bit digits
ct1 resd 1 ;keep track of dec-string size
section .text
pusha; save registers
mov dword[ct1],0 ;initially assume 0
mov edi, decstr ; edi points to dec-string
add edi, 9 ; moved to the last element of string
xor edx, edx ; clear edx for 64-bit div
whileNotZero:
mov ebx, 10 ; get ready to divide by 10
div ebx ; divide by 10
add edx, '0' ; convert to ascii
mov byte[edi], dl ; put it in string
dec edi ; move to next char in str
inc dword[ct1] ; inc char counter
xor edx, edx ; clear edx
cmp eax, 0 ;is remainder 0?
jne whileNotZero ;if no, keep on looping
inc edi ; conversion finished, bring edi
mov ecx, edi ; back to start of string. make ecx
mov edx, [ct1] ; point to counterm edx gets # chars
mov eax, 4 ; print to stdout
mov ebx, 1
int 0x80 ; call kernel
popa ; restore registers
ret
I'm having trouble figuring out how to put a value I currently have in register EAX into an array.
The basic function of this program is to take the dates array, convert them to unique numbers, BubbleSort them, and convert them back.
I put the values I find with "datetonum" into EAX, and I want to store those values I find into my array named ra.
I can't seem to figure out how to do something that.
Seems like it should be fairly simple?
Thanks in advance!
include \masm32\include\masm32rt.inc
.data
dates BYTE "23-JUL-2010", 0, "23-JAN-2010", 0, "23-JUL-2009", 0, "31-JUL-2012", 0, "05-MAR-2010", 0
months BYTE "JAN",0,"FEB",0,"MAR",0,"APR",0,"MAY",0,"JUN",0,"JUL",0,"AUG",0,"SEP",0,"OCT",0,"NOV",0,"DEC",0
nDates DWORD 4
ra DWORD 1,0,0,0,0
.code
start:
lea EAX, dates ; create pointer to beginning of dates array
push EAX
call datetonum
;-------------------
;put value currently in EAX into array to be sorted
;-------------------
print "Array to be sorted contents: "
print chr$(13,10)
lea ECX, ra
mov [ECX + nDates], EAX
print ra
print chr$(13,10)
Here's the datetonum function
;param1 (date string) = address of 12 byte date
datetonum:
enter 4, 0 ; [EBP - 4] holds 4 byte temp variable
mov EBX, [EBP + 8] ; pointer to entire date string
lea ESI, [EBX] ; pointing to day part of date
lea EDI, [EBP - 4] ; pointing to address of local variable to store day string
mov ECX, 2
cld
rep movsb
mov EDX, 0
mov [EDI], EDX ; add null terminator
lea EDX, [EBP - 4]
mov EAX, sval(EDX) ; convert day string to int
push EAX ; push EAX to stack
; extract month from date
lea ESI, [EBX + 3] ; pointing to month part of date
lea EDI, [EBP - 4] ; pointing to address of local variable to store month string
mov ECX, 3
cld
rep movsb
mov EDX, 0
mov [EDI], EDX ; add null terminator
; debug print of month string
pushad
lea EDX, [EBP - 4]
print EDX
print chr$(9) ; print a tab character
print chr$(13,10)
popad
; find month number
sub ESI, ESI
lea EDX, [EBP - 4]
mov EAX, [EDX]
mov ECX, 12
search_top:
lea EDX, [months + ESI * 4]
mov EBX, [EDX]
inc ESI
cmp EAX, EBX
loopne search_top
mov EDX, ESI ; result is in ESI
pop EAX ; pop EAX off the stack
mov AH, DL ; copy the month int into AH
push EAX ; push EAX to stack
; convert year chars to 2 byte int
mov EBX, [EBP + 8]
lea ESI, [EBX + 7] ; pointing to year part of date
lea EDI, [EBP - 4] ; pointing to address of local variable to store year string
mov ECX, 4
cld
rep movsb
mov EDX, 0
mov [EDI], EDX ; add null terminator
lea EDX, [EBP - 4]
mov EDX, sval(EDX) ; convert year string to int
pop EAX ; pop EAX off the stack
mov EBX, EAX ; copy EAX (contains month in AH and day in AL) to EBX
mov EAX, EDX ; copy year to EAX
shl EAX, 16 ; shift the year over to high 16 bits in EAX
mov AX, BX ; copy the month and day into low 16 bits in EAX
;print EAX ; this crashes the proc
print str$(EAX)
print chr$(13,10)
leave
ret 4
exit
If your dates are stored in an array, and you want to use another array to store the dates converted to numbers, you will need at least one loop. You can use index registers (ESI, EDI) to point to both arrays, then use one register to read the value from one array, and the other register to move the value into the other array.
Let's imagine you already have next 3 procedures :
num2date : converts a num in EAX back into a date (the opposite of datetonum). This date is stored in a variable date that is declared like this : date BYTE "DD-MMM-AAAA".
bubble_sort : sorts the numbers in array ra.
transfer_date : takes the 11 bytes of variable date and move them into the position pointed by ESI (ESI is pointing somewhere inside array dates).
This could be the logic of your code :
start:
;▼ NEXT LOOP CONVERTS ALL DATES TO NUMBERS ▼
lea ESI, dates ;POINTER TO ARRAY "DATES".
lea EDI, ra ;POINTER TO ARRAY "RA".
mov ECX, 5 ;LENGTH OF ARRAY "DATES".
dates2numbers:
push ECX ESI EDI ;PRESERVE REGISTERS.
mov EAX, [ESI] ;CURRENT DATE.
push EAX
call datetonum ;CONVERT CURRENT DATE TO A NUMBER.
pop EAX ;GET THE NUMBER.
pop EDI ESI ECX ;RESTORE REGISTERS.
mov [EDI], EAX ;STORE NUMBER IN "RA".
add ESI, 12 ;NEXT ITEM IN ARRAY "DATES" (12 BYTES EACH).
add EDI, 4 ;NEXT ITEM IN ARRAY "RA" (4 BYTES EACH).
loop dates2numbers
call bubble_sort ;◄■■■ SORT ARRAY "RA".
;▼ NEXT LOOP CONVERTS ALL NUMBERS TO DATES ▼
lea ESI, dates ;POINTER TO ARRAY "DATES".
lea EDI, ra ;POINTER TO ARRAY "RA".
mov ECX, 5 ;LENGTH OF ARRAY "RA".
numbers2dates:
push ECX ESI EDI ;PRESERVE REGISTERS.
mov EAX, [EDI] ;CURRENT NUMBER.
call num2date ;CONVERTS EAX TO A DATE IN VARIABLE "DATE".
;VARIABLE "DATE" LOOKS LIKE THIS : DATE BYTE "DD-MMM-AAAA"
;"NUM2DATE" SHOULD PRESERVE ESI AND RESTORE IT
;BECAUSE "TRANSFER_DATE" WILL NEED IT.
call transfer_date ;TRANSFER CONTENT OF VARIABLE "DATE" INTO THE
;ARRAY "DATES" AT THE POSITION ESI IS POINTING TO.
pop EDI ESI ECX ;RESTORE REGISTERS.
add ESI, 12 ;NEXT ITEM IN ARRAY "DATES" (12 BYTES EACH).
add EDI, 4 ;NEXT ITEM IN ARRAY "RA" (4 BYTES EACH).
loop numbers2dates