Weekly Lab 5 :アセンブララボ
4142 ワード
Spo 600(ソフトウェア可搬性と最適化)ブログの週10に戻ってください.今週はラボ5で働きます.この研究室では、AArch 64とx 86 Chain 64システムで、30回動作し、0から30までの数を表示するループを作るための簡単なプログラムを書きます.
<高橋潤子>
AARC 64システム
反射
この研究室は私たちが実際にX 86 Chain 64とAarcha 64システムのプログラミングを踏む最初の研究室です.私のグループと私は全くそれに慣れていないので、かなり難しいです.しかし、6502アセンブリ言語とx 86 six 64とararch 64アセンブリ言語の違いを見るのは楽しいです.彼らは全く異なっていますが、アセンブリ言語として、コーディングスタイルとプログラミングロジックと似たものを見つけるのは難しくありません.
<高橋潤子>
.text
.globl _start
_start:
mov $0, %r15 /* Loop counter */
mov $0x30, %r12 /* value of 0 in Ascii */
loop:
mov $0, %rdx /* clearing reminder for division */
mov %r15, %rax /* set rax to be divide */
mov $10, %r10 /* set divisor */
div %r10 /* divide */
mov %rax, %r14 /* store quotient */
mov %rdx, %r13 /* store remainder */
add $0x30, %r14 /* quotient to ascii */
add $0x30, %r13 /* remainder to ascii */
mov %r13b, msg+7 /* Modify 1 byte inmsg with remainder */
cmp %r12, %r14
mov %r14b, msg+6 /* Modify 1 byte in msg with quotient */
mov $len, %rdx /* message length */
mov $msg, %rsi /* message location */
mov $1, %rdi /* file descriptor stdout */
mov $1, %rax /* syscall sys_write */
syscall
inc %r15 /* increment counter */
cmp $31, %r15 /* see if we're done */
jne loop /* if not, loop */
mov $0, %rdi /* exit status */
mov $60, %rax /* syscall sys_exit */
syscall
.section .data
msg: .ascii "Loop: \n"
len = . - msg
AARC 64システム
.text
.globl _start
_start:
mov x4, 0 /* file descriptor: 1 is stdout */
mov w10, 0x3 /* Value of 0 in ascii */
loop:
add w24, w4, 0x30 /* Converting iterator to ascii */
mov x11, 10 /* Using 10 as a divider */
udiv x12, x4, x11 /* Getting equitent */
msub x13, x11, x12, x4 /* Getting the remainder */
add w14, w12, 0x30 /* Ascii conversion */
add w15, w13, 0x30 /* Ascii conversion */
adr x16, msg /* Storing the message */
strb w15, [x16, 7] /* Storing remainder into msg at byte 7 */
cmp w14, w10 /* Is 0 */
strb w14, [x16, 6] /* Storing quotient in msg at byte 6 */
mov x0, 1 /* file descriptor */
adr x1, msg /* message location (memory address) */
mov x2, len /* message length (bytes) */
mov x8, 64 /* write is syscall #64 */
svc 0 /* invoke syscall */
add x4, x4, 1
cmp x4, 31 /* Checks if the iterator equals 31 */
b.ne loop
mov x0, 0 /* status -> 0 */
mov x8, 93 /* exit is syscall #93 */
svc 0 /* invoke syscall */
.data
msg: .ascii "Loop: \n"
len= . - msg
両方のシステムで結果は同じです:反射
この研究室は私たちが実際にX 86 Chain 64とAarcha 64システムのプログラミングを踏む最初の研究室です.私のグループと私は全くそれに慣れていないので、かなり難しいです.しかし、6502アセンブリ言語とx 86 six 64とararch 64アセンブリ言語の違いを見るのは楽しいです.彼らは全く異なっていますが、アセンブリ言語として、コーディングスタイルとプログラミングロジックと似たものを見つけるのは難しくありません.
Reference
この問題について(Weekly Lab 5 :アセンブララボ), 我々は、より多くの情報をここで見つけました https://dev.to/qzhang125/spo600-64-bit-lab-5-assembler-lab-20glテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol