Translate formula DELTA = B^2 - 4AC to an assembly language program

Viewed 99

I'm totally a beginner in the assembly language. I'm trying to translate b^2-4ac in assembly code for simple calculation. This is my code and I can't figure out how I can display the output of this program.
Note: When I run this code in Visual Studio 2019, this executes without any error but doesn't show any output.

This is my code:

.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword

.data

delta   SDWORD ?
a   SDWORD 6
b   SDWORD 3
cc   SDWORD 4

.code
main proc

    ; b^2-4ac
    mov eax,a 
    mov ebx,b
    mov ecx,cc

    imul ebx,b ; b^2
    imul eax,4 ; 4a
    imul eax,cc ; 4a*c
    sub ebx,eax ; b^2-4ac

    mov delta,ebx ; delta = b^2-4ac

    invoke ExitProcess,0
main endp
end main
1 Answers

There are multiple ways that you could do that. The easiest would be to leverage one of the suitable Windows API functions. For example:

include \masm32\include\msvcrt.inc
includelib \masm32\lib\msvcrt.lib

.data
fmtString       db "delta =  %d",13,10,0

.code

; ..other stuff..

invoke crt_printf,ADDR fmtString,ebx
Related