i just learn this in a short semester like only 6 week. still confuse about the whole assembly language thing, this code is also used chatgpt to correct some error and this is the final version that the chatgpt gave me. still it have problem and i don't know where is the problem. The command prompt just blank after i run the code.
this is how it looks like when i run the code 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
the answe i expect in decimal is 12417.
After my last answer (which was not so good) I decided to return to idea from first post. Calculations + output. Prints 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