Tasm local variables

风格不统一 提交于 2019-12-24 11:23:29

问题


Using Tasm 1.4 and trying to create and manipulate local variables in procedure:

findMins PROC
    local z:word:1 ;outer loop counter
    local j:word:1 ;inner loop counter
    mov cx, rows ;outer loop total iterations
    mov z, 0 
    RowsLoop:
        push cx ; save outer iterations left
        mov cx,cols ; inner iterations
        mov j, 2
        ColsLoop:
        //some code
        loop ColsLoop
        //some code
    loop RowsLoop       
    ret
ENDP

mov j, 2 this instruction changes both j and z local variables. How should I create variables that seen only inside function and they are different, e.g I don't want to change the second variable with operation mov j, 2.


回答1:


Your function header is not complete. To force Turbo Assembler to create epilogues and prologues you have to add a language (e.g. C or PASCAL): findMins PROC C

To make the variables (and other symbols) local you have to prefix @@ (e.g. @@z) and to add at the beginning of the program LOCALS:

LOCALS
.MODEL small
.STACK 1000h
.DATA
    rows dw 3
    cols dw 7
.CODE
main PROC
    MOV ax, @data
    MOV ds, ax

    call findMins

    mov ax, 4C00h
    int 21h

main ENDP

findMins PROC C
    local @@z:word:1 ;outer loop counter
    local @@j:word:1 ;inner loop counter
    mov cx, rows ;outer loop total iterations
    mov @@z, 0
    RowsLoop:
        push cx ; save outer iterations left
        mov cx,cols ; inner iterations
        mov @@j, 2
        ColsLoop:
        ;some code
        loop ColsLoop
        ;some code
    loop RowsLoop
    ret
ENDP

END main


来源:https://stackoverflow.com/questions/27201947/tasm-local-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!