アセンブリ言語第1部


今日は6502プロセッサから動いて64ビットアセンブリ言語で動作します.今回の私の課題は2つのアセンブリコードの例、AARC 64アーキテクチャのための1つ、x 86 . 64 64のための他のものをビルドすることです.
まず最初に、私はAarcha 64プログラムで働きます.出発点は以下の通りです.
.text
.globl _start

min = 0                          /* starting value for the loop index; note that this is a symbol (constant), not a variable */
max = 30                         /* loop exits when the index hits this number (loop condition is i<max) */

_start:

    mov     x19, min

loop:

    /* ... body of the loop ... do something useful here ... */

    add     x19, x19, 1
    cmp     x19, max
    b.ne    loop

    mov     x0, 0           /* status -> 0 */
    mov     x8, 93          /* exit is syscall #93 */
    svc     0               /* invoke syscall */
このコードは30に達するまでループしますが、ループ内では何もしません.私たちの最初のタスクは、ループの繰り返しが実行されるたびに印刷を変更することです.メッセージを印刷するために私たちに提供されたいくつかのコードを加えることによって、我々は以下を得ます:
.text
.globl _start

min = 0                          /* starting value for the loop index; note that this is a symbol (constant), not a variable */
max = 10                         /* loop exits when the index hits this number (loop condition is i<max) */

_start:

    mov     x19, min

loop:

    mov     x0, 1           /* file descriptor: 1 is stdout */
    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     x19, x19, 1 
    cmp     x19, max
    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
出力は
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
次のループは、ループを繰り返すたびに反復する番号を印刷するループを取得することです.このようなコードを修正しました.
.text
.globl _start

min = 0                          /* starting value for the loop index; note that this is a symbol (constant), not a variable */
max = 10                         /* loop exits when the index hits this number (loop condition is i<max) */

_start:

    mov     x19, min

loop:

    add    x18, x19, '0'         
    adr    x17, msg+6            
    strb   w18, [x17]            

    mov     x0, 1                /* file descriptor: 1 is stdout */
    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     x19, x19, 1       
    cmp     x19, max
    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
適切な出力を得た.
Loop: 0
Loop: 1
Loop: 2
Loop: 3
Loop: 4
Loop: 5
Loop: 6
Loop: 7
Loop: 8
Loop: 9
次回は30回まで繰り返し実行しますが、その後はx 86 six 64アーキテクチャで同じように取り組みます.もっとすぐに!