E
E
evgeniybaklajanov2018-10-04 13:46:42
C++ / C#
evgeniybaklajanov, 2018-10-04 13:46:42

How to translate a C or C++ program into a MASM/TASM assembly language program?

How to translate a C or C++ program into a MASM/TASM assembly language program?
I always get GAS syntax.
I was taught a task, I did it, but it is necessary in assembler.
Visual Studio is swinging for a long time, you need something very light (I can’t have a lot of Internet :)).
PS 1 It is not necessary to advise freelancing 2 I'll figure it out with a prog on asma.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-10-04
@evgeniybaklajanov

First, what you call GAS syntax is actually called AT&T syntax. And the syntax used in MASM/TASM is Intel syntax. Secondly, what does the teacher expect from you?

.section .data

hello_str:
    .ascii "Hello, world!\n"
    .set hello_str_length, . - hello_str


.section .text

.global main
.type main, @function

main:
    movq    $4, %rax
    movq    $1, %rbx
    movq    $hello_str, %rcx
    movq    $hello_str_length, %rdx
    int     $0x80

    movq    $1, %rax
    movq    $0, %rbx
    int     $0x80

.size main, . - main

What will you get as a result of translating the C code
.file   "test.c"
        .section        .rodata
.LC0:
        .string "Hello, World!"
        .text
        .globl  main
        .type   main, @function
main:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        subq    $16, %rsp
        movl    %edi, -4(%rbp)
        movq    %rsi, -16(%rbp)
        leaq    .LC0(%rip), %rdi
        call    [email protected]
        movl    $0, %eax
        leave
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
.LFE0:
        .size   main, .-main
        .ident  "GCC: (Debian 6.3.0-18) 6.3.0 20170516"
        .section        .note.GNU-stack,"",@progbits

I think even a loser will notice the difference, not to mention the teacher. In addition to the "extra" code, characteristic unreadable marks and digital offsets, the C-code uses library calls instead of system calls.
But if you still want to try your luck, then here's what was googled in ten seconds - https://godbolt.org/

D
devalone, 2018-10-04
@devalone

I was taught a task, I did it, but it is necessary in assembler.

If the task is to write a program in assembler, then you need to do it that way, compilers generate code for machines, not people, and the goal is to understand how it works at the machine level.
If you still have a desire, look for instructions for any compiler, for gcc like this:
g++ main.cpp -S
or like this with intel syntax:
g++ main.cpp -S -masm=intel
You don't even have to download anything https://godbolt.org /

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question