|
-
Nov 20th, 2000, 10:41 AM
#1
Thread Starter
Member
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.
sums.asm
Code:
PUBLIC _sums
.MODEL small
.CODE
_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++
_sums ENDP
ENDC
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.
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!
Thanx, Matt
VB5 Enterprise, C++Builder 5, JBuilder 3.5 (so far unused  )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|