rajpoot mhm
rajpoot mhm

Reputation: 21

The console output is not displayed when calling from Irvine, but it returns a value to 'c', which can then be printed on the console

main.c


#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

    // Declare the assembly function
    extern int add_func(int a, int b);

#ifdef __cplusplus
}
#endif

int main() {

    printf("Starting the assembly function...\n");
    int result = add_func(2, 3);
    printf("Result: %d\n", result);

    return 0;
}


Include irvine32.inc

.model flat, STDCALL

.data
    result DWORD ?
    
.code

add_func PROC

    ; Save the base pointer
    push ebp
    mov ebp, esp

    ; Get the arguments
    mov eax, [ebp+8]  ; a
    mov ecx, [ebp+12] ; b

    ; Add a and b
    add eax, ecx

    ; Store the result in a variable
    mov result, eax
    
    call WriteInt

exit_function:

    ; Restore the base pointer
    pop ebp

    ; Return the result in EAX
    mov eax, result
    ret 8  ; Clean up the stack (2 arguments * 4 bytes each)

add_func ENDP

END

No Output for Irvine WriteInt

I want to use assembly to write to the console or perform other standard calls. My environment is set up properly for regular assembly; it prints to the console easily using write int. However, I need to ensure that the setup works for other standard calls as well.

Successful Runing only .asm with irvine32

Upvotes: 0

Views: 91

Answers (1)

rajpoot mhm
rajpoot mhm

Reputation: 21

ThanksGiving Michael Petch

Include irvine32.inc

; irvine32.inc already uses this directive for us:
; .model flat, STDCALL

.data
result DWORD ?

.code

add_func PROC C

    ; Save the base pointer
    push ebp
    mov ebp, esp

    ; Get the arguments
    mov eax, [ebp+8] ; a
    mov ecx, [ebp+12] ; b

    ; Add a and b
    add eax, ecx

    ; Store the result in a variable
    mov result, eax

    call WriteInt

    exit_function:

    ; Restore the base pointer
    pop ebp

    ; Return the result in EAX
    mov eax, result
    ret

add_func ENDP

END

Upvotes: 1

Related Questions