Pointers mov函数指针中的基本汇编

Pointers mov函数指针中的基本汇编,pointers,assembly,mov,Pointers,Assembly,Mov,我想在指针中输入一个新值(他指向他的值),但我失败了 程序被推到堆栈中 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 n

我想在指针中输入一个新值(他指向他的值),但我失败了

程序被推到堆栈中

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更大,则有必要跳过标签“大”
下面是代码和一些小补丁:

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