从堆栈及其段中更新位于数据段中的变量

发布于 2024-11-19 16:49:18 字数 989 浏览 3 评论 0原文

我目前有三个内存段,我的主数据段、堆栈段和我的 API 所在的段。以下指令是从数据段执行的,它们推送cursorRow 和welcomeMsg 的地址,然后对我的API 段中的函数进行远程调用。 cursorRow 变量位于调用 API 函数的主数据段中。该调用如下所示:

  push cursorRow
  push welcomeMsg
  call API_SEGMENT:API_printString

如何通过堆栈更改 API 所在段内的cursorRow? cursorRow 需要从 API 更新。没有 API 函数会更改数据段。我尝试过以下操作:inc byte [ds:bp+8]add [ds:bp+8], 1。 以下是正在调用的 API 过程:

printStringProc:
    push bp 
    mov bp, sp
    mov si, [bp+6]
    .printloop:
        lodsb
        cmp al, 0
        je printStringDone
        mov ah, 0x0E ; teletype output
        mov bh, 0x00 ; page number
        mov bl, 0x07 ; color (only in graphic mode)
        int 0x10
        jmp .printloop
    printStringDone:
    ; move the cursor down
    mov ah, 02h ; move cursor
    mov dh, [bp+8]
    mov dl, 0 ; column
    mov bh, 0 ; page number
    int 10h

    add [ds:bp+8], 1

  pop bp
  retf 

它打印字符串,但cursorRow 变量未正确更新。我希望我对我的问题足够清楚。很难解释:D

I currently have three segments of memory, my main data segment, stack segment and the segment where my API lives. The following instructions are executed from the data segment, they push the address of cursorRow and welcomeMsg then do a far call to the function in my API segment. The cursorRow variable lives in the main data segment that is calling the API function. The call looks like this:

  push cursorRow
  push welcomeMsg
  call API_SEGMENT:API_printString

How can I alter cursorRow, inside of the segment where my API lives, through the stack? cursorRow needs to be updated from the API. NO API functions alter the data segment. I have tried things like: inc byte [ds:bp+8] and add [ds:bp+8], 1.
Here is the API procedure being called:

printStringProc:
    push bp 
    mov bp, sp
    mov si, [bp+6]
    .printloop:
        lodsb
        cmp al, 0
        je printStringDone
        mov ah, 0x0E ; teletype output
        mov bh, 0x00 ; page number
        mov bl, 0x07 ; color (only in graphic mode)
        int 0x10
        jmp .printloop
    printStringDone:
    ; move the cursor down
    mov ah, 02h ; move cursor
    mov dh, [bp+8]
    mov dl, 0 ; column
    mov bh, 0 ; page number
    int 10h

    add [ds:bp+8], 1

  pop bp
  retf 

it prints strings, but the cursorRow variable doesn't correctly update. I hope I'm clear enough on my issue. It's hard to explain :D

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

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

发布评论

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

评论(2

不寐倦长更 2024-11-26 16:49:18

这是因为您将指针传递给了cursorRow,而不是cursorRow 本身。当您执行时

inc [ds:bp+8]

:1) 获取 bp 的值,2) 添加 8,3) 假设结果是 ds 中的指针,4) 递增存储在那里的值(指向光标行的指针)。由于指针存储在堆栈中,因此执行此操作时会递增指针。您需要做的是将指针从堆栈中取出并增加指向的值

mov bx, [bp+8]
inc [bx]

此代码:1) 获取 bp 的值,2) 加 8,3) 假设结果是 ss 中的指针,4) 加载存储在那里的值(指向cursorRow的指针)到bx中,5)假设bxds中的指针,6)递增存储在那里的值(cursorRow的值)。

This is because you passed the pointer to cursorRow, not cursorRow itself. When you perform

inc [ds:bp+8]

you: 1) get the value of bp, 2) add 8, 3) assume the result is a pointer in ds, 4) increment the value stored there (the pointer to cursorRow). Since the pointer is stored on the stack, you are incrementing the pointer when you do this. What you need to do is take the pointer off of the stack and increment the value that points to.

mov bx, [bp+8]
inc [bx]

This code: 1) gets the value of bp, 2) adds 8, 3) assumes the result is a pointer in ss, 4) load the value stored there (the pointer to cursorRow) into bx, 5) assumes bx is a pointer in ds, 6) increments the value stored there (the value of cursorRow).

葮薆情 2024-11-26 16:49:18

看起来您刚刚将cursorRow 的值推入堆栈。如果没有地址,您将无法更新它。通过该地址,您可以轻松引用该地址的值,将其放入寄存器中,对其执行操作,然后取出该寄存器中的值并将其放入光标行的地址中。

It's look like you just pushed the value of cursorRow onto the stack. Without the address you cannot update it. With the address you can easily reference that addresses' value, put it into a register, perform operations on it, then take the value that's in that register and put it into the address of cursorRow.

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