Jump to content

Need help with AT&T assembly

- - - - -

  • Please log in to reply
5 replies to this topic

#1
your_rock

your_rock

    Newbie

  • Members
  • Pip
  • 8 posts
Hi,

I've got an assignment where I have to turn C code into machine and assembly code, but I'm having a problem with understanding beq, bne, blt, and bnl commands. I have to do a simple while loop (while i >= 0), and I'm guessing I have to use bnl command but I have no idea how to use it. Anyone can provide me a link to learn about branching or can tell me about will be much appreciated. Also I have to use AT&T syntax, not Intel one.

Thanks in advance.

#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
For the following C code,
while (variable1 < variable2){ 

  variable2 += variable3; 

} 

I would usually do something like this:
lp1: 

  mov eax, dword [variable1] 

  cmp eax, dword [variable2] 

  jnl lp1s 

  

  mov eax, dword [variable3] 

  add dword [variable2], eax 

  

  jmp lp1 

lp1s: 

I don't know AT&T syntax, though; this is just my two cents.

#3
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Are you using MIPS, x86, or what? I'm not sure whether beq, bne, blt, or bnl exists on x86, and that is why I ask.
Latinamne loqueris?

#4
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
I think the 'b' - in beq, bne, blt, and bnl - stands for "branch" (verb).

#5
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Yeah, beq, bne, blt, and bnl are MIPS instructions. What did your assignment say?
sudo rm -rf /

#6
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
You would still use very similar instructions on MIPS, as you would on x86. Like instead of using the 'jz' instruction, you would use the 'beq' instruction, etc.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users