1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #Load a doubleword (64 bits) from the address specified by #register 3 + register 20 and store the value into register 31 ldx 31, 3, 20 #Load a byte from the address specified by register 10 + register 12 #and store the value into register 15 and zero-out remaining bits lbzx 15, 10, 12 #Load a halfword (16 bits) from the address specified by #register 6 + register 7 and store the value into register 8, #sign-extending the result through the remaining bits lhax 8, 6, 7 #Take the doubleword (64 bits) in register 20 and store it in the #address specified by register 10 + register 11 stdx 20, 10, 11 #Take the doubleword (64 bits) in register 20 and store it in the #address specified by register 10 + register 11, and then update #register 10 with the final address stdux 20, 10, 11 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ###DATA DEFINITIONS### .data .align 3 first_value: .quad 1 second_value: .quad 2 ###ENTRY POINT DECLARATION### .section .opd, "aw" .align 3 .globl _start _start: .quad ._start, .TOC.@tocbase, 0 ###CODE### .text ._start: ##Load values## #Load the address of first_value into register 7 from the global offset table ld 7, first_value@got(2) #Use the address to load the value of first_value into register 4 ld 4, 0(7) #Load the address of second_value into register 7 from the global offset table ld 7, second_value@got(2) #Use the address to load the value of second_value into register 5 ld 5, 0(7) ##Perform addition## add 3, 4, 5 ##Exit with status## li 0, 1 sc |
1 2 3 4 5 6 7 8 9 10 11 | #Assemble as -a64 addnumbers.s -o addnumbers.o #Link ld -melf64ppc addnumbers.o -o addnumbers #Run ./addnumbers #View the result code (value returned from the program) echo $? |
1 2 3 | .section .toc name: .tc unused_name[TC], initial_value |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | ### DATA ### #Create the variable my_var in the table of contents .section .toc my_var: .tc [TC], 10 ### ENTRY POINT DECLARATION ### .section .opd, "aw" .align 3 .globl _start _start: .quad ._start, .TOC.@tocbase, 0 ### CODE ### .text ._start: #loads the number 10 (my_var contents) into register 3 ld 3, my_var@toc(2) #loads the address of my_var into register 4 ld 4, my_var@got(2) #loads the number 10 (my_var contents) into register 4 ld 3, 0(4) #load the number 15 into register 5 li 5, 15 #store 15 (register 5) into my_var via ToC std 5, my_var@toc(2) #store 15 (register 5) into my_var via GOT (offset already loaded into register 4) std 5, 0(4) #Exit with status 0 li 0, 1 li 3, 0 sc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ### PROGRAM DATA ### #Create the values in the table of contents .section .toc first_value: .tc [TC], 1 second_value: .tc [TC], 2 ### ENTRY POINT DEFINITION ### .section .opd, "aw" .align 3 .globl _start _start: .quad ._start, .TOC.@tocbase, 0 .text ._start: ##Load values from the table of contents ## ld 4, first_value@toc(2) ld 5, second_value@toc(2) ##Perform addition## add 3, 4, 5 ##Exit with status## li 0, 1 sc |
1 2 3 4 5 6 7 8 9 10 11 12 | #Starting at the address specified in register ten, load #the next 32 bytes into registers 24-31 lmw 24, 0(10) #Starting at the address specified in register 8, load #the next 8 bytes into registers 30-31 lmw 30, 0(8) #Starting at the address specified in register 5, store #the low-order 32-bits of registers 20-31 into the next #48 bytes stmw 20, 0(5) |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |