APH Networks | community: Assembly is some fun stuff - APH Networks | community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Assembly is some fun stuff

#1 User is offline   chconline 

  • Editor-in-Chief
  • Group: Executive Staff Team
  • Posts: 26,199
  • Joined: 22-October 04
  • Gender:Male
  • Location:Calgary, Alberta

Posted 28 January 2010 - 10:39 PM

C:

int a1[8] = { 0x333, 0x777, 0x111, 0x444, 0x888, 0x222, 0x666, 0x555 };
int a2[8] = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x80, 0x70 };

int main(int argc, char **argv, char **envp)
{
  int i_min;
  int i;
  int *p1;
  int *p2;
  int *beyond;

  /* Search for index of smallest element of a1, put result in i_min */
  i_min = 0;
  for (i = 1; i < 8; i++)
    if (a1[i] < a1[i_min])
      i_min = i;

  /* Copy array elements from a1 to a2 in reverse order, overwriting
   * the initial values in a2. */
  p1 = a1 + 7;
  p2 = a2;
  beyond = p2 + 8;
  while (p2 != beyond) {
    *p2 = *p1;
    p1--;
    p2++;
  }

  return 0;
}


MIPS Assembly (Partial):

main:
        add     $s0, $zero, $zero      
        addi	$s1, $zero, 1			
        addi	$t0, $zero, 8			
        la		$s2, a1					
        la		$s3, a2					
        
beg_loop:
		slt		$t1, $s1, $t0			
        beq		$t1, $zero, end_loop	
        sll		$t2, $s1, 2				
        add		$t3, $s2, $t2			
        lw		$t4, ($t3)				
        sll		$t5, $s0, 2				
        add		$t6, $s2, $t5			
        lw		$t7, ($t6)				
        slt		$t8, $t4, $t7			
        beq		$t8, $zero, end_if		
        add		$s0, $zero, $s1			
end_if:
        addi	$s1, $s1, 1				
		j		beg_loop				   
end_loop:

		addi	$s4, $s2, 28			
		add		$s5, $zero, $s3			


And so on...

Generally speaking, I hate Assembly already.
Posted Image

#2 User is offline   TL6MT 

  • I drive an Acura TL SH-AWD 6MT
  • Group: +Subscriber
  • Posts: 3,329
  • Joined: 16-June 09
  • Gender:Male
  • Location:Los Angeles

Posted 29 January 2010 - 04:50 PM

Wow that means nothing to me - how can anyone actually understand that ****?
Posted Image
1

#3 User is offline   shc-boomer 

  • News Director
  • Group: Staff Team
  • Posts: 11,089
  • Joined: 24-October 04
  • Gender:Male
  • Location:Vancouver, BC, Canada

Posted 29 January 2010 - 08:32 PM

Assembly is not fun at all. Too bad I have to learn it soon.
Posted Image

#4 User is offline   Big Bang 

  • APH Platinum
  • Group: +Subscriber
  • Posts: 2,982
  • Joined: 30-October 06
  • Gender:Male

Posted 02 February 2010 - 09:58 AM

What the hell is the $s0 stuff?
Posted Image
Camaro SS FTW
1

#5 User is offline   chconline 

  • Editor-in-Chief
  • Group: Executive Staff Team
  • Posts: 26,199
  • Joined: 22-October 04
  • Gender:Male
  • Location:Calgary, Alberta

Posted 02 February 2010 - 10:02 AM

Those are register names in MIPS Assembly. Kind of like a variable, except you don't get fancy user friendly names. :P
Posted Image

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic