为什么我的 Masm615/Win32 代码没有向控制台输出结果或错误?

问题描述 投票:0回答:1

我只是在短短的一个学期(比如只有六周)内学会了这一点。仍然对整个汇编语言的事情感到困惑,这段代码也使用 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。

assembly x86 console-application masm irvine32
1个回答
-1
投票

在我最后的回答(不太好)之后,我决定回到第一篇文章的想法。计算+输出。打印 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
© www.soinside.com 2019 - 2024. All rights reserved.