开发者

Probably a really newb Question (asm in V C++)

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开发者_Go百科 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).


Although I'm not sure, I'd guess that LENGTHOF NUMS is only the length of the first line. Try using only one WORD keyword and either put it on one line or use commas or something. I'm not familiar enough with MASM to say exactly how you should do that.


The handling of the pcount variable is really unclear, but sure looks wrong. I'm guessing it counts words written on each line. When it reaches 9, you'd only want to output a crlf, then reset the value back to 0. That's not happening, it will equal 9 only once.

The next thing to watch out for is what the helper functions do to the register variables. I don't remember the exact rules but I think you can only assume that the values of esi and edi are preserved. You need to push/pop the rest.

Use the debugger.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜