Presentation is loading. Please wait.

Presentation is loading. Please wait.

Architecture Chapter 2 - Supplement Additional Features In Chapter 2.

Similar presentations


Presentation on theme: "Architecture Chapter 2 - Supplement Additional Features In Chapter 2."— Presentation transcript:

1 Architecture Chapter 2 - Supplement Additional Features In Chapter 2

2 /****************************************************************** To look at big endian and little endian. ******************************************************************/ union xx { long lval; char cval[4]; } xunion; int main( int argc, char *argv[] ) { int index; xunion.lval = 1; if ( argc > 1 ) xunion.lval = atol(argv[1] ); printf( "Address of lval: %x\n", &xunion.lval ); for (index = 0; index < 4; index++ ) printf( "Byte %d: Address = %x, Contents = %d\n", index, &(xunion.cval[index]), xunion.cval[index] ); } /* End of main */

3 This is the output when run on Intel Little-Ended-ness babbage% a.out Address of lval: 804969c Byte 0: Address = 804969c, Contents = 1 Byte 1: Address = 804969d, Contents = 0 Byte 2: Address = 804969e, Contents = 0 Byte 3: Address = 804969f, Contents = 0 babbage% a.out 256 Address of lval: 804969c Byte 0: Address = 804969c, Contents = 0 Byte 1: Address = 804969d, Contents = 1 Byte 2: Address = 804969e, Contents = 0 Byte 3: Address = 804969f, Contents = 0

4 This is the output when run on HP PA-RISC Big-Ended-ness -> a.out Address of lval: bc98 Byte 0: Address = bc98, Contents = 0 Byte 1: Address = bc99, Contents = 0 Byte 2: Address = bc9a, Contents = 0 Byte 3: Address = bc9b, Contents = 1 ready 09:24:06 -> a.out 256 Address of lval: bc98 Byte 0: Address = bc98, Contents = 0 Byte 1: Address = bc99, Contents = 0 Byte 2: Address = bc9a, Contents = 1 Byte 3: Address = bc9b, Contents = 0 ready 09:24:20

5 PA-RISC Assembler Output int main( int argc, char *argv[] ) 000000A0: 6BC23FD9 stw %r2,-20(%sp) #14 000000A4 6FC30080 stwm %r3,64(%sp) 000000A8 6BC43F89 stw %r4,-60(%sp) 000000AC 6BC53F91 stw %r5,-56(%sp) if ( argc > 1 ) LINE 19 xunion.lval = 1; LINE 18 000000B0 2B600000 addil L%0,%dp #18 000000B4 34330000 ldo 0(%r1),%r19 000000B8 4A650009 ldw -8188(%r19),%r5 000000BC B4130002 addi 1,%r0,%r19 000000C0 8F424028 comib,>= 1,%r26,0x000000DC #19.l386 000000C4 68B30000 stw %r19,0(%r5) #18 xunion.lval xunion.lval = atol(argv[1] ); LINE 20 000000C8 47330008 ldh 4(%r25),%r19 #20 ->char 000000CC 473A000C ldh 6(%r25),%r26 ->char 000000D0 E84000C8 bl 0x0000013C,%r2 atol 000000D4 D7530E10 dep %r19,15,16,%r26 000000D8 68BC0000 stw %r28,0(%r5) xunion.lval

6 PA-RISC Assembler Output printf( "Address of lval: %x\n", &xunion.lval ); LINE 21 000000DC: E8600000 bl 0x000000E4,%r3 #21 000000E0 D4601C1E depi 0,31,2,%r3 000000E4 34633E39 ldo -228(%r3),%r3 000000E8 B47A0060 addi 48,%r3,%r26 000000EC E8400078 bl 0x00000130,%r2 printf 000000F0 34B90000 copy %r5,%r25 for (index = 0; index < 4; index++ ) LINE 22 000000F4 34040000 ldi 0,%r4 #22 MOVED FROM LINE 23 000000F8 B4630010 addi 8,%r3,%r3 #23 printf( "Byte %d: Address = %x, Contents = %d\n", index, &(xunion.cval[index]), xunion.cval[index] ); LINE 23 000000FC: 0CA40017 ldbx %r4(%r5),%r23 #23 xunion.cval 00000100: 08A40A18 addl %r4,%r5,%r24 00000104 347A0000 copy %r3,%r26 00000108 E8400040 bl 0x00000130,%r2 printf 0000010C 34990000 copy %r4,%r25 00000110 B4840002 addi 1,%r4,%r4 00000114 8C887FCF comib,>,n 4,%r4,0x00000100.l501 00000118 0CA40017 ldbx %r4(%r5),%r23 xunion.cval } /* End of main */

7 Intel Assembler Output main: pushl %ebp movl %esp,%ebp subl $24,%esp movl $1,xunion cmpl $1,8(%ebp) jle.L3 addl $-12,%esp movl 12(%ebp),%eax addl $4,%eax movl (%eax),%edx pushl %edx call atol addl $16,%esp movl %eax,%eax movl %eax,xunion.L3: addl $-8,%esp pushl $xunion pushl $.LC0 call printf addl $16,%esp movl $0,-4(%ebp).L4: cmpl $3,-4(%ebp) jle.L7 jmp.L5.L7: movl -4(%ebp),%eax movl $xunion,%edx movsbl (%eax,%edx),%eax pushl %eax movl $xunion,%edx movl %edx,%eax addl -4(%ebp),%eax pushl %eax movl -4(%ebp),%eax pushl %eax pushl $.LC1 call printf addl $16,%esp.L6: incl -4(%ebp) jmp.L4.L5:.L2: leave ret


Download ppt "Architecture Chapter 2 - Supplement Additional Features In Chapter 2."

Similar presentations


Ads by Google