Skip to content

I found a strange issue when using multiplication (*=) and one of the operands is 1. #8

@zzdmfk

Description

@zzdmfk

C code:
`int printf(const char* str, ...);

int main()
{
int x = 1;
x *= 100;
printf("%d\r\n", x);
}`

asm code:

section .data section .text extern _printf global main ; main function main: push ebp mov ebp, esp sub esp, 16 push dword 1 pop eax mov dword [ebp-4], eax push dword 100 pop eax mov ecx, eax mov eax, [ebp-4] imul eax mov dword [ebp-4], eax lea ebx, [_printf] push ebx pop ebx mov dword [function_call_1], ebx push dword [ebp-4] mov eax, str_2 push eax call [function_call_1] add esp, 8 push eax pop eax push eax add esp, 4 add esp, 16 pop ebp ret section .data function_call_1: dd 0 section .rodata str_2: db '%', 'd', 0

The function printf always outputs 1, but I change int x = 1 to int x = 2, it outputs correctly. Can you tell me why? the multiplication operand can not be 1?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions