更新变量住在数据段从堆栈和其细分市场 [英] Updating variable that lives in the data segment from the stack and its segment

查看:183
本文介绍了更新变量住在数据段从堆栈和其细分市场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司目前拥有的内存,我主要的数据段,堆栈段和段在我的生活API三个部分。下面的说明是从数据段执行,他们推cursorRow和welcomeMsg的地址,然后做一个远调用我的API段的功能。该cursorRow变量生活正在调用API函数的主要数据段。调用看起来是这样的:

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

我怎样才能改变cursorRow,段内的在我的生命API,通过堆栈? cursorRow需要从API更新。否API函数改变数据段。我曾尝试喜欢的东西: INC字节[DS:BP + 8] 添加[DS:BP + 8],1
下面是API过程被称为:

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 

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

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

推荐答案

这是因为你传递的指针cursorRow,不cursorRow本身。当您执行

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

inc [ds:bp+8]

您:1)获得 BP 的值,2)加8,3)假设结果是 DS指针,4)增加存储在那里的​​值(指针cursorRow)。由于指针存储在堆栈上,你当你这样做递增指针。你需要做的就是把指针从堆栈和增加值的的点。

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]

这code:1)获得 BP 的值,2)增加了8,3)假设结果是指针SS ,4)存储在那里(指针cursorRow)值加载到 BX ,5)假定 BX DS指针 6)增加存储在那里的​​值(cursorRow的值)。

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

这篇关于更新变量住在数据段从堆栈和其细分市场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆