How to compile with Bruce's C Compiler to get asm file that runs on 8086 processors

1.5k views Asked by At

I have this small c code

    int main (){
    int in  [50];
    int res [50];

    int avg=0;
    int i=0;
    int j=0;

    for(i=0;i<50;i++){
      in[i]=i*5+28%25;
    }

    for(i=0;i<50;i++){
        avg=0;
        for(j=i-4;j<=i+5;j++){
            if((j>=0)&&(j<50)){
                avg=avg+in[j];
            }
            avg=avg/10;
            res[i]=avg;
        }
    }
    return 0;
}

which is a simple moving average function

I want to get the assembly code that corresponds to this code, however, I want the x86 ISA assembly code that can run on processor 8086

after looking I ran this commands

bcc -ansi -c -o foo.o foo.c
as86 foo.asm -o foo.o

this ended up with error

as: error opening input file

how can I compile my file to get the assembly code?

1

There are 1 answers

2
fuz On BEST ANSWER

Try bcc -S to get assembly. For example, if you type bcc -ansi -S foo.c you get foo.s with the following content (debug comments removed for brevitiy):

export  _main
_main:
push    bp
mov bp,sp
push    di
push    si
add sp,#-$CA
xor ax,ax
mov -$CE[bp],ax
dec sp
dec sp
xor ax,ax
mov -$D0[bp],ax
dec sp
dec sp
xor ax,ax
mov -$D2[bp],ax
xor ax,ax
mov -$D0[bp],ax
jmp .3
.4:
mov ax,-$D0[bp]
mov dx,ax
shl ax,*1
shl ax,*1
add ax,dx
add ax,*3
push    ax
mov ax,-$D0[bp]
shl ax,*1
mov bx,bp
add bx,ax
mov ax,-$D4[bp]
mov -$68[bx],ax
inc sp
inc sp
.2:
mov ax,-$D0[bp]
inc ax
mov -$D0[bp],ax
.3:
mov ax,-$D0[bp]
cmp ax,*$32
jl  .4
.5:
.1:
xor ax,ax
mov -$D0[bp],ax
jmp .8
.9:
xor ax,ax
mov -$CE[bp],ax
mov ax,-$D0[bp]
add ax,*-4
mov -$D2[bp],ax
jmp .C
.D:
mov ax,-$D2[bp]
test    ax,ax
jl      .E
.10:
mov ax,-$D2[bp]
cmp ax,*$32
jge     .E
.F:
mov ax,-$D2[bp]
shl ax,*1
mov bx,bp
add bx,ax
mov ax,-$CE[bp]
add ax,-$68[bx]
mov -$CE[bp],ax
.E:
mov ax,-$CE[bp]
mov bx,*$A
cwd
idiv    bx
mov -$CE[bp],ax
mov ax,-$D0[bp]
shl ax,*1
mov bx,bp
add bx,ax
mov ax,-$CE[bp]
mov -$CC[bx],ax
.B:
mov ax,-$D2[bp]
inc ax
mov -$D2[bp],ax
.C:
mov ax,-$D0[bp]
add ax,*5
cmp ax,-$D2[bp]
jge .D
.11:
.A:
.7:
mov ax,-$D0[bp]
inc ax
mov -$D0[bp],ax
.8:
mov ax,-$D0[bp]
cmp ax,*$32
blt     .9
.12:
.6:
xor ax,ax
lea sp,-4[bp]
pop si
pop di
pop bp
ret
.data
.bss