assembly 为什么我的Masm 615/Win32代码不向控制台输出结果或错误?

js4nwp54  于 2023-10-19  发布在  其他
关注(0)|答案(1)|浏览(130)

我只是在短短的一个学期里学会了这个,只有6个星期。仍然对整个汇编语言的事情感到困惑,这段代码也是使用chatgpt来纠正一些错误,这是chatgpt给我的最终版本。但还是有问题,我不知道问题出在哪里。运行代码后命令提示符为空。
这是当我运行代码Output of the code时的样子

TITLE AssignmentP2 (Mult.asm)
; This program calculates the value using the following data
; Val1 = 340d
; Val2 = A3Ch
; Val3 = 45h
; FinalVal = -(Val1 – Val3) + 1 + (Val2 * 3) + 1 + 1 – 2 -1– (Val1 / 2)

INCLUDE Irvine32.inc
INCLUDE macros.inc  ; Include macros for WriteDec and Crlf

.data
Val1 dword 340d
Val2 dword 0A3Ch
Val3 dword 45h

.code
main proc
    mov eax, [Val1]  ; Load Val1 into eax
    sub eax, [Val3]  ; Subtract Val3 from eax
    neg eax          ; Negate eax (2's complement)
    inc eax          ; Add 1 to eax
    mov ebx, [Val2]  ; Load Val2 into ebx
    imul ebx, 3      ; Multiply ebx by 3
    add eax, ebx     ; Add ebx to eax
    inc eax          ; Add 1 to eax
    inc eax          ; Add 1 to eax
    sub eax, 2       ; Subtract 2 from eax
    dec eax          ; Subtract 1 from eax

    mov edx, eax     ; Preserve the result in edx
    mov ebx, [Val1]  ; Load Val1 into ebx
    mov ecx, 2       ; Divisor (2)
    div ecx          ; Divide eax by ecx (Val1 / 2)
    mov ecx, eax     ; Store the result (Val1 / 2) in ecx
    mov eax, edx     ; Restore the preserved result into eax

    call WriteDec    ; Call WriteDec to print the result

main endp

end main

我希望十进制的答案是12417。

gstyhher

gstyhher1#

在我的最后一个答案(这不是那么好),我决定回到第一个职位的想法。计算+输出。指纹7419.

TITLE AssignmentP2 (Mult.asm)
; This program calculates the value using the following data
; Val1 = 340d
; Val2 = A3Ch
; Val3 = 45h
; FinalVal = -(Val1 – Val3) + 1 + (Val2 * 3) + 1 + 1 – 2 -1– (Val1 / 2)
                    
include \masm32\include\Irvine32.inc
includelib \masm32\lib\Irvine32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.data
Val1 dword 340d  
Val2 dword 0A3Ch  ; 2620       
Val3 dword 45h    ; 69             

.code
main proc
    mov eax, [Val1]  ; Load Val1 into eax
  
    sub eax, [Val3]  ; Subtract Val3 from eax
    
    neg eax          ; Negate eax (2's complement)
    
    inc eax          ; Add 1 to eax
    
    mov ebx, [Val2]  ; Load Val2 into ebx
    
    imul ebx, 3      ; Multiply ebx by 3

    add eax, ebx     ; Add ebx to eax

    inc eax          ; Add 1 to eax
    
    inc eax          ; Add 1 to eax

    sub eax, 2       ; Subtract 2 from eax
    
    dec eax          ; Subtract 1 from eax

    mov ebx, [Val1]  ; Load Val1 into ebx

    shr ebx, 1       ; divide value in ebx by 2
   
    sub eax, ebx     ; Substract value in ebx from eax                      

    call WriteDec
    exit
    ret
main endp

end main

相关问题