I just started working with assembly so this is probably a really simple question, but I can't figure it out at all.
I have created a table with these values in it:
EDIT
.data
NUMS WORD 09EEBh, 0B0CFh, 061E5h, 089EDh, 0AF17h, 0D8D1h, 06C1Dh, 0594Eh, 0CF55h
WORD 0AFFFh, 05B8Fh, 06164h, 01CF7h, 09A41h, 0A525h, 0A5A1h, 08F05h, 07E4Ch
WORD 0827Ah, 090B0h, 0722Dh, 0BCCFh, 033ABh, 0DC76h, 085B6h, 0AA5Fh, 03FB3h
WORD 04BACh, 0B822h, 07768h, 0BF1Bh, 05783h, 07EEBh, 09F22h, 0B85Bh, 05312h
WORD 05971h, 0B1B6h, 0B16Dh, 054B3h, 073C8h, 0586Bh, 08170h, 06F16h, 092A0h
WORD 09680h, 0A23Bh, 0B45Dh, 01E91h, 0415Ah, 0B5D9h, 02D02h, 06748h, 03D39h
NUMS_SIZE EQU $-NUMS
NUMS_LENGTH EQU (NUMS_SIZE / TYPE NUMS)
.code
But when I run my subroutine to print out all the values in NUMS in it only prints the first row. Could anyone tell me why it's not printing the whole table?
Here's the way I'm printing the table:
printUnsort proc ; print out unsorted table
mov ecx, NUMS_LENGTH
mov edi,0
mov edx, OFFSET s
.WHILE ecx > 0
.IF pcount != 9
mov ax, (NUMS[di])
call WriteHexB
call WriteString
add edi, TYPE NUMS
inc ax
dec ecx
inc pcount
.ELSE
Call CrLf
mov pcount, 0
.ENDIF
.ENDW
ret
printUnsort endp
Any help or advice would be very helpful. Thank you! =)
The problem here is that LENGTHOF (and also SIZEOF) assumes the array begins and ends with the single data declaration. In your case, this is 9 words, regardless of the fact you have 45 more words following it. There are generally two ways to fix this:
Use a single data declaration (note the use of the line continuation):
NUMS WORD 1, 2, 3, 4, \
5, 6, 7, 8, \
...
However, you'll likely run into MASM's line length limitations with your declaration on a single line. Therefore, you could use this workaround by placing it immediately following your original declaration of NUMS:
NUMS_SIZE EQU $-NUMS
NUMS_LENGTH EQU (NUMS_SIZE / TYPE NUMS)
And use "NUMS_LENGTH" instead of LENGTHOF NUMS. NUMS_SIZE will be the the size of the array in bytes (the current location minus where the array starts).