반복문

 

%inlucde "io64.inc"

section .text

global CMAIN

CMAIN:

;write your code here

mov ax, 0

mov ecx, 10

 

L_loop:

add ax, cx

loop L_loop

 

PRINT_DEC 2, ax

NEWLINE

 

xor rax, rax

ret

 

inc,  1증가

 

%include "io64.inc"

 

section .text

global CMAIN

CMAIN:

;write your code here

mov ax,0

mov bx,1

mov cx,10

L_L1:

add ax,bx

inc bx

loop L_L1

 

PRINT_DEC 2, ax

NEWLINE

 

xor rax, rax

ret

 

 

 

do while

 

%include "io64.inc"

 

section .text

global CMAIN

CMAIN:

;write your code here

mov ax,0

mov bx,0

L1:

add ax, bx

inc bx

cmp bx, 10

jle L1

 

PRINT_DEC 2,ax

NEWLINE

xor rax, rax

ret

 

 

while

 

%include "io64.inc"

 

section .text

global CMAIN

CMAIN:

;write your code here

mov ax,0

mov bx,0

L1:

cmp bx, 10

jg L2

add ax, bx

inc bx

jmp L1

L2:

PRINT_DEC 2, ax

NEWLINE

xor rax, rax

ret

 

 

배열 접근하기 

 

include "io64.inc"

 

section .text

global CMAIN

CMAIN:

;write your code here

mov al, [a]

PRINT_DEC 1, al

NEWLINE

 

mov al, [a+1]; a는 1바이트 크기

PRINT_DEC 1, al

NEWLINE

 

mov ax, [b]

PRINT_HEX 2, ax

NEWLINE

 

mov ax, [b + 1 * 2]

PRINT_HEX 2, ax

NEWLINE

 

mov ax, [b + 2 * 2]

PRINT_DEC 2, ax

NEWLINE

 

xor rax, rax

ret

 

section .data

a db 30,50,60

b dw 0x1234, 0x5678, 10

 

배열 복사.

포인트는 괄호 내부안에 들어가는 레지스터 변수는 무조건 4바이트 변수로 넣을것 밑에 보면 인덱스를 굳이 eax로 한 이유임 

include "io64.inc"

 

section .text

global CMAIN

CMAIN:

;write your code here

mov eax, 0

mov ecx, 3

 

L1:

mov ebx,[origin + eax * 2]; eax에 인덱스값을 저장 2바이트크기 변수임

mov [copy + eax * 2], ebx

inc eax

loop L1

 

mov edx, copy;edx에 copy시작주소를 넣음.. 왜?

mov eax, 0

L2:

PRINT_HEX 2, [edx + eax * 2]

NEWLINE

inc eax

cmp eax,3

jl L2

 

xor rax, rax

ret

 

section .data

origin dw 0x1234,0x4567, 0x8912

section .bss

copy resw 3

 

 

'NASM' 카테고리의 다른 글

9일차  (0) 2020.06.23
8일차.  (0) 2020.06.21
6일차.  (0) 2020.06.19
5일차.  (0) 2020.06.18
4일차.  (0) 2020.06.17

+ Recent posts