3 Replies - 3829 Views - Last Post: 03 June 2012 - 02:02 AM

#1 jerriwest1988   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-April 12

transforming some c code to lc 2200 assembly code

Posted 01 June 2012 - 09:36 PM

Hello,

This is the C Code:


	a = getAValue();
	if (a == B)/> {
	    c = a + b;
	}
	else {
	    c = a - b;
        }


I need this to be transform into lc 2200 assembly code. Don't worry about the lc 2200 spec. I just want to know the logic.

I know how to handle the if and else statement. It basically will be a brz deal, branch on zero. I don't know how to handle the a = getAValue(); I know you can ld a value into register, but how do you know a function call to a variable?

Thanks,
Jerri

Is This A Good Question/Topic? 0
  • +

Replies To: transforming some c code to lc 2200 assembly code

#2 GunnerInc   User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 917
  • View blog
  • Posts: 2,358
  • Joined: 28-March 11

Re: transforming some c code to lc 2200 assembly code

Posted 01 June 2012 - 09:46 PM

Moved to assembly
Was This Post Helpful? 0
  • +
  • -

#3 GunnerInc   User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 917
  • View blog
  • Posts: 2,358
  • Joined: 28-March 11

Re: transforming some c code to lc 2200 assembly code

Posted 01 June 2012 - 10:07 PM

Quote

Don't worry about the lc 2200 spec

Then don't worry about a correct answer. When writing in Assembly, specs are probably one of the most important details you need to know, especially when asking for help from others.

In x86, almost all functions return their values in the EAX register. If your code is not going to interact with others, you can return a value in almost any register. That being said, what is register does the Little Computer use to hold function return values?
Was This Post Helpful? 0
  • +
  • -

#4 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 168
  • View blog
  • Posts: 1,077
  • Joined: 03-April 12

Re: transforming some c code to lc 2200 assembly code

Posted 03 June 2012 - 02:01 AM

Is that LC 2200 the imaginary 32-bit processor used for teaching, like LC 3?

I found something like that,and the LC 2200 I found talks about seemed to use 32-bit MIPS assembly subset.

MIPS ABI (register usage) can be found here.

Maybe this description of instructions is enough for you.

The if else structure:
I gon't know how the getAValue(); is called in your environment-

; t2 is variable a after getting the value

        XOR $t1, $t1, $t1 ;clear t1
        ADDIU $t1 $zero B ; load immediate B

        BEQ $t1 $t2 then
        ; else-part here
        J endif
then:
        ; then-part here
endif:


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1