mov 函数指针中的基本汇编

Basic assembly in mov function pointers

我想将一个新值放入一个指针中(在他指向他的值中)但是我失败了。

程序入栈

offset result, num1 and num2

最大化需要在结果中...

现在我需要你的帮助

org  100h

jmp main

    result      dw ?
    num0        dw ?
    num1        dw ?


main:  
    mov bp,sp     
    push (offset result) 
    push num0 
    push num1
    call max
    MOV AX,num0
    call print_num
    PRINTN
    MOV AX,num1
    call print_num
    PRINTN
    MOV AX,result
    call print_num
    PRINTN 
    ret

max PROC

    push bp        
    mov bp,sp
    MOV AX,[BP+6]
    MOV BX,[BP+4]
    MOV CX,[BP+2]
    CMP AX,BX
    JGE BIG
    MOV [CX],BX 
BIG:
    MOV [CX],AX  
    mov sp,bp
    pop bp
    ret

max ENDP


include magshimim.inc \our program built for us defines for the inputs...

我想做:

MOV [CX] , AX

但是emu8086不太喜欢我:)

感谢您的帮助!

发现的问题:

  • "push (offset result)" 似乎因为括号存储了错误的值。
  • 程序"max"一开始,BP就被压栈,所以参数不再是BP+6、+4、+2,而是BP+8、+6、+ 4.
  • “[CX]”不能当指针,我们改成BX。
  • 如果 CX 更大,则有必要跳过标签 "BIG"。

下面是稍作修改的代码:

org  100h

jmp main

    result      dw ?
    num0        dw 5    ;VALUE TO TEST.
    num1        dw 2    ;VALUE TO TEST.


main:  
    mov bp,sp     
    push offset result  ;PARENTHESIS SEEM TO STORE THE WRONG VALUE.
    push num0 
    push num1
    call max
    MOV AX,num0
    call print_num
    PRINTN
    MOV AX,num1
    call print_num
    PRINTN
    MOV AX,result
    call print_num
    PRINTN 
    ret

max PROC

    push bp         ;"BP" IN STACK. PARAMTERS ARE NO LONGER IN BP+6,+4,+2.
    mov bp,sp

    MOV BX,[BP+8]   ;BX = RESULT'S ADDRESS.
    MOV AX,[BP+6]   ;AX = NUM0'S VALUE.
    MOV CX,[BP+4]   ;CX = NUM1'S VALUE.
    CMP AX,CX
    JGE BIG
    MOV [BX],CX 
    jmp finish      ;NECESSARY TO SKIP "BIG".
BIG:
    MOV [BX],AX  
;    mov sp,bp
finish:
    pop bp
    ret

max ENDP