#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Location
    UK
    Posts
    2
    Rep Power
    0

    MIPS Assembly EL/EB byte order


    Hello, I might have gotten byte ording incorrect, and I was wonder if I can confirm this with someone...
    I have this ASM code from a picture frame firmware. the 32bit CPU is definalty little-endian.
    Code:
    LoopAgain:      # Rearrange 8 btyes
    	lw      $t0, 0($t4)      # 0x11223344 e.g.
    	lw      $t1, 4($t4)      # 0x55667788 e.g.
    	move    $s1, $t1         # "
    	move    $a0, $t1         # "
    	lui     $at, 0xFF00
    	and     $t1, $at         # 0x55000000
    	srl     $a0, 8           # 0x00556677
    	andi    $a0, 0xFF00      # 0x00006600
    	add     $t1, $a0         # 0x55006600
    	move    $s2, $t0
    	move    $a0, $t0
    	srl     $t0, 8           # 0x00112233
    	lui     $at, 0xFF
    	and     $t0, $at         # 0x00110000
    	srl     $a0, 16          # 0x00001122
    	andi    $a0, 0xFF        # 0x00000022
    	add     $t0, $a0, $t0    # 0x00110022
    	add     $t2, $t0, $t1    # 0x55116622 - 1st Combined
    	move    $t1, $s1         # 2nd String
    	move    $t0, $s2         # 1st String
    	move    $s1, $t0         # 1st String
    	move    $a0, $t0         # 1st String
    	sll     $t0, 16          # 0x33440000
    	lui     $at, 0xFF00
    	and     $t0, $at         # 0x33000000
    	sll     $a0, 8           # 0x22334400
    	andi    $a0, 0xFF00      # 0x00004400
    	add     $t0, $a0         # 0x33004400
    	move    $s2, $t1         # 2nd String
    	move    $a0, $t1         # 2nd String
    	andi    $t1, 0xFF        # 0x00000088
    	sll     $a0, 8           # 0x66778800
    	lui     $at, 0xFF
    	and     $a0, $at         # 0x00770000
    	add     $t1, $a0         # 0x00770088
    	add     $t3, $t1, $t0    # 0x33774488 - 2nd Combined
    	move    $t0, $s1         # 1st String
    	move    $t1, $s2         # 2nd String
    	move    $s1, $t2         # 1st Combined
    	sll     $t2, 16          # 0x66220000
    	lui     $at, 0xFFFF
    	and     $t2, $at         # 0x66220000 ??
    	move    $s2, $t3         # 2nd Combined
    	andi    $t3, 0xFFFF      # 0x00004488
    	add     $t0, $t2, $t3    # 0x66224488 - 3rd Combined
    	move    $t2, $s1         # 1st Combined
    	move    $t3, $s2         # 2nd Combined
    	move    $s1, $t2         # 1st Combined
    	srl     $t2, 16          # 0x00005511
    	andi    $t2, 0xFFFF      # 0x00005511 ??
    	move    $s2, $t3         # 2nd Combined
    	lui     $at, 0xFFFF
    	and     $t3, $at         # 0x33770000
    	add     $t1, $t2, $t3    # 0x33775511 - 4th Combined
    	move    $t2, $s1
    	move    $t3, $s1
    	sw      $t0, 0($t4)      # 0x66224488 !
    	sw      $t1, 4($t4)      # 0x33775511 !
    	add     $t4, $t6
    	add     $t0, $t4, $t6
    	sltu    $at, $t5, $t4
    	bnez    $at, CarryOn
    	nop
    	b       LoopAgain
    	nop
    CarryOn:
    I have commented the memory arrangement next to the code.
    For EB, the result should be 0x66224488 & 0x33775511. But would the result be different for EL, or should it not make any difference in this context?

    Like for example would:
    > lui $at, 0xFF00 (Load Upper 16 Immediate)
    be this: 0xFF000000 or 0x000000FF or unlightly this 0x00FF0000, on a little-endian chip.

    Matt
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Location
    UK
    Posts
    2
    Rep Power
    0
    I see now, the answer is 'no difference in this context'
    e.g. 44332211,88776655 = 88442266,11557733
    which is the same just byte swapped the very first and very last values for EL...

IMN logo majestic logo threadwatch logo seochat tools logo