Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   urgent: please EXPERTS: convert C to assembly (http://www.programmingforums.org/showthread.php?t=2381)

samra Feb 21st, 2005 10:17 AM

urgent: please EXPERTS: convert C to assembly
 
HI, i am new here & i urgently need help :o
I need to rewrite this code in assembly language making the right adjusments
:

INTEGER B = 0
INTEGER C = 10
INTEGER D = 100
for (A= 15 ; A>=0; A--)
{
B += C;
IF (B >= D)
B += C;
}


please please please i really need this urgently iam drawning in search & iam new in programming :( . help me. my professor will kill me
& i will appreciate your help very much it really means alot for me.

Dizzutch Feb 21st, 2005 10:59 AM

gcc -S file.c ..:)
your professor should be there for questions, go see him. We can teach you assembley in a post.

samra Feb 21st, 2005 1:23 PM

:) thanku. nice to take time & reply.
u think i want the nswer ready?
well, no it's not this.
our pro. is not the kind of professors that might answer.
this is just a course in microprocessor lab & he gave us the assignment & did not teach us these stuff (self study i think)
but i am new & i really spent a lot of hours searching & i didn't get it. it's all driving me crazy with all the code & commands i see & i don't understand a bit.
+ i searched 3 books & not get any clue :confused:
is this it? u won't help me??? :(

ok just give me aclue & i will continue my self.
i want to learn please :)
regards

tempest Feb 21st, 2005 2:29 PM

:

        .file  "test.c"
        .text
.globl main
        .type  main, @function
main:
        pushl  %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        andl    $-16, %esp
        movl    $0, %eax
        subl    %eax, %esp
        movl    $0, -4(%ebp)
        movl    $10, -8(%ebp)
        movl    $100, -12(%ebp)
        movl    $15, -16(%ebp)
.L2:
        cmpl    $0, -16(%ebp)
        jns    .L5
        jmp    .L3
.L5:
        movl    -8(%ebp), %eax
        leal    -4(%ebp), %edx
        addl    %eax, (%edx)
        movl    -4(%ebp), %eax
        cmpl    -12(%ebp), %eax
        jl      .L4
        movl    -8(%ebp), %edx
        leal    -4(%ebp), %eax
        addl    %edx, (%eax)
.L4:
        leal    -16(%ebp), %eax
        decl    (%eax)
        jmp    .L2
.L3:
        movl    $0, %eax
        leave
        ret
        .size  main, .-main
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.3.5 (Debian 1:3.3.5-3)"


Mjordan2nd Feb 21st, 2005 7:32 PM

Quote:

Originally Posted by samra
+ i searched 3 books & not get any clue :confused:
is this it? u won't help me??? :(

ok just give me aclue & i will continue my self.
i want to learn please :)
regards

Dizzutch was trying to help you. What he was saying, is that if you have a copy of the GNU C compiler, then using the command he gave will turn your C code into assembly code.

samra Feb 22nd, 2005 12:50 AM

thanku Dizzutch, tempest, Machiavelli, and all those who passed by.
i am sorrrrrrry for the misunderstanding. but i am REALLY NEW. & feel bad about my unconsciousness. in fact i use command prompt (DEBUG) to write the code, till now we have not met any of the assemblers i saw many talk about in the internet, like MASM, RASM etc.. if i am not wrong.
again thanks alot. & sorry for not mentioning this in the beginning.
& tempest i dont get the code u wrote, :o sorry
here is the code i felt will work but am not sure coz i don't know how to test :confused:
:

        MOV BX,0  ; THIS IS THE B=0
        MOV CX,10 ; THIS IS THE COUNTER a=15
        MOV AX,A  ; AX=C = 10
        MOV DX,64 ; D=100
ONE :CMP CX,0
        DEC CX
        JGE LP
LP:    ADD BX,AX
        CMP BX,DX
        JL ONE
        JGE LP
        HLT

any body know what i am talking about, if u dont mind check. & tell me whats wrong or what should be corrected?

Christian_Rosenkreuz_777 Feb 22nd, 2005 7:07 PM

In the debug util. . .
 
I don't know exactly how much you know, so I'll walk you through this step by step (btw, this is on how to test your program).

1.) type 'a'
2.) type your code
3.) type 'n'+(insert desired name of program here)+'.com' or '.exe' (depends on
presence or lack of stack; since you're a newbie, it's probably .com)
4.) type 'RCX'
5.) type 'A'
6.) type 'w'
7.) type 'q'
now just go to the directory where your program was and run the program by the name you gave it in step 3 (minus the 'n')
Hope this helps. I know assembly's hard (trust me) :)

samra Mar 2nd, 2005 11:11 PM

thank you, i couldnot follow. & yes assembly is difficult. right now we are using the turbo pascal editor.
regards

liquidsilver Mar 11th, 2005 2:53 PM

I suggest you download MASM (or the likes) as it just makes it soo much easier.

Thanx for that gcc tip, I never new :)


All times are GMT -5. The time now is 10:55 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC