可能是一个非常新的问题(V C 中的 asm++)

发布于 2024-10-20 13:29:26 字数 1283 浏览 2 评论 0原文

我刚刚开始使用汇编,所以这可能是一个非常简单的问题,但我根本无法弄清楚。

我创建了一个包含这些值的表:

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

但是当我运行子例程来打印 NUMS 中的所有值时,它只打印第一行。谁能告诉我为什么它不打印整个表格?

这是我打印表格的方式:

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

任何帮助或建议都会非常有帮助。谢谢你! =)

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! =)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

︶ ̄淡然 2024-10-27 13:29:26

这里的问题是 LENGTHOF (以及 SIZEOF)假设数组以单个数据声明开始和结束。在您的例子中,这是 9 个单词,尽管后面还有 45 个单词。通常有两种方法可以解决此问题:

使用单个数据声明(请注意行延续的使用):

NUMS WORD 1, 2, 3, 4, \
          5, 6, 7, 8, \
          ...

但是,您可能会在单行上声明时遇到 MASM 的行长度限制。因此,您可以通过将其紧跟在原始 NUMS 声明之后来使用此解决方法:

NUMS_SIZE EQU $-NUMS
NUMS_LENGTH EQU (NUMS_SIZE / TYPE NUMS)

并使用“NUMS_LENGTH”而不是 LENGTHOF NUMS。 NUMS_SIZE 是数组的大小(以字节为单位)(当前位置减去数组的起始位置)。

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).

少年亿悲伤 2024-10-27 13:29:26

虽然我不确定,但我猜 LENGTHOF NUMS 只是第一行的长度。尝试仅使用一个 WORD 关键字,并将其放在一行或使用逗号或其他内容。我对 MASM 不太熟悉,无法准确说明您应该如何做到这一点。

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.

雨落星ぅ辰 2024-10-27 13:29:26

pcount 变量的处理确实不清楚,但看起来肯定是错误的。我猜它会计算每行写的字数。当它达到 9 时,您想要输出一个 crlf,然后值重置回 0。这种情况不会发生,它只会等于 9 一次。

接下来要注意的是辅助函数对寄存器变量的作用。我不记得确切的规则,但我认为你只能假设 esi 和 edi 的值被保留。您需要推送/弹出其余部分。

使用调试器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文