This is the same test piece that now creates a fixed array and copies the tokenised text into the fixed array.
It does one pass through the tokenised lines to get the maximum line length. It allocates the fixed array based off the original array calculation of the maximum line length then copies the original array content to the fixed array.
The purpose of this test piece is to take tokenised data done in place and copy it to an array of fixed member length with additional space so that the lines can be modified up to the new longer length.
As before, the win64.inc file is not included to keep the file size down.
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
include \masm64\include64\masm64rt.inc
.code
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
entry_point proc
USING r12, r13, r14 ; nominate registers to protect
LOCAL pMem :QWORD ; source memory pointer
LOCAL flth :QWORD ; file length
LOCAL parr :QWORD ; pointer array
LOCAL lcnt :QWORD ; file line count
LOCAL mlen :QWORD ; max length var
LOCAL pfix :QWORD ; fixed array pointer
LOCAL lfix :QWORD ; fixed array member length
SaveRegs ; preserve nominated registers
mov pMem, loadfile("win64.inc")
mov flth, rcx ; store the file length
rcall lntok,pMem ; call the tokeniser
mov parr, rax ; load the array pointer
mov lcnt, rcx ; get the line count
conout "Line count = ",str$(lcnt),lf
mov mlen, 0 ; set max at 0
; -----------------------------------------
mov r12, lcnt ; load them into protected registers
mov r13, parr
lbl:
.if len(QWORD PTR [r13]) }= mlen
mov mlen, len(QWORD PTR [r13]) ; get the longest line length
.endif
add r13, 8 ; QWORD spacing in array
sub r12, 1
jnz lbl
; -----------------------------------------
conout "max line len = ",str$(mlen),lf
mov r14, mlen ; load longest length into r14
add r14, r14 ; double it for extra room
mov lfix, r14 ; store it in a variable
rcall fixed_array,lcnt,lfix ; allocate a fixed array
mov pfix, rax
waitkey "Holding My Breath, press any key ...."
; -----------------------------------------
mov r12, lcnt ; load them into protected registers
mov r13, parr
mov r14, pfix
lbl2:
rcall szCopy,QWORD PTR [r13],QWORD PTR [r14]
conout QWORD PTR [r14],lf ; display the copied content
add r13, 8 ; QWORD spacing in array
sub r12, 1
jnz lbl2
; -----------------------------------------
mfree pfix
mfree pMem ; free source memory
mfree parr ; free array memory
waitkey " Arrrgh, thats all folks ...." ; pause at the end to see results
RestoreRegs ; restore nominated registers
.exit ; bye
entry_point endp
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
end