나누기 2바이트 이상

 

%include "io64.inc"

 

section .text

global CMAIN

CMAIN:

;write your code here

mov eax, 0x12345678 ;305419896

mov bx, 0x4567 ;17767

 

mov edx, eax

shr edx, 16

and eax, 0x0000ffff

div bx

mov [quotient], ax

mov [remainder], dx

 

PRINT_HEX 2, quotient

NEWLINE

PRINT_DEC 2, quotient

NEWLINE

PRINT_HEX 2, remainder

NEWLINE

PRINT_DEC 2, remainder

NEWLINE

 

xor rax, rax

ret

section .bss

quotient resw 1

remainder resw 1

 

TEST매크로 zf설정 관찰하기

 

%include "io64.inc"

 

section .text

global CMAIN

CMAIN:

mov rbp, rsp; for correct debugging

;write your code here

 

mov ax, 0x1234

and ax, 0x0000; zf설정됨 ax값도 변경됨

PRINT_HEX 2, ax

NEWLINE

 

add ax, 0x1234; zf가 설정된게 풀어짐

mov ax, 0x1234

test ax,0x0000; zf값은 설정되나 ax값은 변경안됨

PRINT_HEX 2, ax

NEWLINE

 

 

xor rax, rax

ret

 

 

 if문의 구현,  cmp와 jmp이용

je : 같다면 

%include "io64.inc"

 

section .text

global CMAIN

CMAIN:

;write your code here

mov ax, 20

mov bx, 10

 

cmp ax,bx ;ax 와 bx를 비교연산을 할것이다.

je L_equal ; ax와bx가 같다면 L_equal 라벨로 이동 하라

mov cx, 0 ; 위 라인의 je가 실행이 안됐다면 실행됨, ax와bx가 다름

jmp L_equal_end ;무조건 L_eqaul_end로 이동 goto문인듯

 

L_equal:

mov cx, 100

 

L_equal_end:

PRINT_DEC 2,cx

NEWLINE

 

xor rax, rax

ret

 

 

위와 같은 기능을 하나 순서를 다르게한 소스

%include "io64.inc"

 

section .text

global CMAIN

CMAIN:

;write your code here

mov ax, 20

mov bx, 10

 

cmp ax,bx

je L_equal

jmp L_not_equal

L_equal:

mov cx, 100

jmp L_eqaul_end

L_not_equal:

mov cx, 0

L_eqaul_end:

PRINT_DEC 2, cx

 

xor rax, rax

ret

 

위와 같은 기능을 하나 또다른 소스 jne로 jne:같지 않다면

%include "io64.inc"

 

section .text

global CMAIN

CMAIN:

;write your code here

mov ax,20

mov bx,10

 

cmp ax,bx

jne L_not_equal

 

;ax bx 같다면

mov cx, 100

jmp L_not_equal_end

L_not_equal:

mov cx, 0

L_not_equal_end:

PRINT_HEX 2, cx

 

xor rax, rax

ret

 

'NASM' 카테고리의 다른 글

7일차.  (0) 2020.06.20
6일차.  (0) 2020.06.19
4일차.  (0) 2020.06.17
3일차.  (0) 2020.06.17
2일차  (0) 2020.06.15

+ Recent posts