从堆栈及其段中更新位于数据段中的变量
我目前有三个内存段,我的主数据段、堆栈段和我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为您将指针传递给了cursorRow,而不是cursorRow 本身。当您执行时
:1) 获取
bp
的值,2) 添加 8,3) 假设结果是ds
中的指针,4) 递增存储在那里的值(指向光标行的指针)。由于指针存储在堆栈中,因此执行此操作时会递增指针。您需要做的是将指针从堆栈中取出并增加指向的值。此代码:1) 获取
bp
的值,2) 加 8,3) 假设结果是ss
中的指针,4) 加载存储在那里的值(指向cursorRow的指针)到bx
中,5)假设bx
是ds
中的指针,6)递增存储在那里的值(cursorRow的值)。This is because you passed the pointer to cursorRow, not cursorRow itself. When you perform
you: 1) get the value of
bp
, 2) add 8, 3) assume the result is a pointer inds
, 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.This code: 1) gets the value of
bp
, 2) adds 8, 3) assumes the result is a pointer inss
, 4) load the value stored there (the pointer to cursorRow) intobx
, 5) assumesbx
is a pointer inds
, 6) increments the value stored there (the value of cursorRow).看起来您刚刚将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.