How is it that this sample of asm code won't work? It's the very first example in the book as well
Imagine you have a 2d pyramid of blocks. Each row will have one more block than the row above it. This routine is supposed to calculate the number of blocks in the pyramid when given the number of blocks on the last row.
It's designed to be called from Borland C++ using the syntax SUMS(X). It only ever returns 0.
The only thing I thought of is that CX is never decremented each time round the loop - hence given the value 7 at start it will continue adding 7 each time round the loop until eventaully AX is overflowed.
_sums PROC Value:WORD
MOV AX, 0 ;Initialise to zero
MOV CX, Value ;Get actual value
JCXZ S3 ;Num=0, no need to do
CLC ;Initialise for start
S1: ADC AX, CX ;Add row value
JC S2 ;Quit if AX overflowed
LOOP S1 ;Repeat process
JMP S3 ;Successful completion
S2: MOV AX, 0 ;Force a zeor
S3: RET ;Return to C++
Even adding the line SUB CX, 1 in that loop didn't work though. I'm using TASM that came with C++ Builder 5.5.
Am I right in thinking that once this routine (and any other routine I write) has been called the reult will be placed in AX, or is this dependent on what I write?
Sorry for so many questions, but as you can see I've only just started!