RJ90 0 Posted December 1, 2010 Report Share Posted December 1, 2010 Boas pessoal! É assim, preciso de ajuda de alguém que esteja a usar GCC, pois eu não uso e não sei como usar (até porque uso Windows). O que queria era gerar o Assembler output de um programa que tenho em C. int num = 0; int all = 0; int res = 0; int soma = 0; puts("Input: "); scanf_s("%d", &num); while (all < num) { all++; res = all % 2; if (res ==1) { soma += all; } else { continue; } } printf("Output: %d",soma); Pelo que eu vi por ai, deve-se usar a opção -S para criar o ficheiro com o Assembler Output. Algo como: gcc -S omeuprogemc.c ou ainda(decidir o nome do ficheiro a criar) gcc -S -o oficheiroassembler.s omeuprogemc.c De GCC não percebo grande coisa, nem sei se dá para windows. Agradecia um ajuda, quem criar o ficheiro .s, upava para um host sff, ou então, dizer alguma maneira de fazer isto. ________ Tentei com o MinGW, mas dá erros: O resultado é: .file "myfile.c" ◣ Samsung 700Z5A-S01PT ◥ ◣ Samsung Ominia W ◥ ᥡ What Else? ᥡ Link to post Share on other sites
Baderous 31 Posted December 2, 2010 Report Share Posted December 2, 2010 Suponho que esse código esteja dentro da função main e tenha um return no fim e etc. Depois estás a usar a função scanf_s que apenas existe nos sistemas Microsoft. Portanto, supondo que o código é este: #include <stdio.h> int main(void) { int num = 0; int all = 0; int res = 0; int soma = 0; puts("Input: "); scanf("%d", &num); while (all < num) { all++; res = all % 2; if (res ==1) { soma += all; } else { continue; } } printf("Output: %d",soma); return 0; } O ficheiro Assembly correspondente é: .cstring LC0: .ascii "Input: \0" LC1: .ascii "%d\0" LC2: .ascii "Output: %d\0" .text .globl _main _main: LFB3: pushq %rbp LCFI0: movq %rsp, %rbp LCFI1: subq $16, %rsp LCFI2: movl $0, -4(%rbp) movl $0, -8(%rbp) movl $0, -12(%rbp) movl $0, -16(%rbp) leaq LC0(%rip), %rdi call _puts leaq -4(%rbp), %rsi leaq LC1(%rip), %rdi movl $0, %eax call _scanf jmp L2 L3: incl -8(%rbp) movl -8(%rbp), %edx movl %edx, %eax sarl $31, %eax movl %eax, %ecx shrl $31, %ecx leal (%rdx,%rcx), %eax andl $1, %eax subl %ecx, %eax movl %eax, -12(%rbp) cmpl $1, -12(%rbp) jne L2 movl -8(%rbp), %eax addl %eax, -16(%rbp) L2: movl -4(%rbp), %eax cmpl %eax, -8(%rbp) jl L3 movl -16(%rbp), %esi leaq LC2(%rip), %rdi movl $0, %eax call _printf movl $0, %eax leave ret LFE3: .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support EH_frame1: .set L$set$0,LECIE1-LSCIE1 .long L$set$0 LSCIE1: .long 0x0 .byte 0x1 .ascii "zR\0" .byte 0x1 .byte 0x78 .byte 0x10 .byte 0x1 .byte 0x10 .byte 0xc .byte 0x7 .byte 0x8 .byte 0x90 .byte 0x1 .align 3 LECIE1: .globl _main.eh _main.eh: LSFDE1: .set L$set$1,LEFDE1-LASFDE1 .long L$set$1 LASFDE1: .long LASFDE1-EH_frame1 .quad LFB3-. .set L$set$2,LFE3-LFB3 .quad L$set$2 .byte 0x0 .byte 0x4 .set L$set$3,LCFI0-LFB3 .long L$set$3 .byte 0xe .byte 0x10 .byte 0x86 .byte 0x2 .byte 0x4 .set L$set$4,LCFI1-LCFI0 .long L$set$4 .byte 0xd .byte 0x6 .align 3 LEFDE1: .subsections_via_symbols Link to post Share on other sites
RJ90 0 Posted December 2, 2010 Author Report Share Posted December 2, 2010 Obrigado Baderous! Estou agora a tentar criar o programa em Assembly x86, mas estou uma beca :dontgetit: org 100h; ;******* ;* Var * ;******* ALL DB 0 ;*************** ;* Pedir Valor * ;*************** .DATA PROMPT DB "Input:" .CODE ;*************** ;* Pedir Valor * ;*************** LEA DX, PROMPT MOV AH, 9 INT 21H ;************* ;* Ler Valor * ;************* MOV AH, 1 INT 21H MOV BL, AL ;Guardar o numero em BL ;************ ;* Condição * ;************ WHILE: MOV EAX, ALL CMP EAX, BL JNBE END_WHILE INC ALL ;Incrementa ALL Alguém me pode ajudar? ◣ Samsung 700Z5A-S01PT ◥ ◣ Samsung Ominia W ◥ ᥡ What Else? ᥡ Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now