nasm 에서 입력받는 매크로 10진
GET_DEC 바이트수, 주소
%include "io64.inc"
section .text
global CMAIN
CMAIN:
;write your code here
GET_DEC 1, al
GET_DEC 2,a
PRINT_DEC 1,al
NEWLINE
PRINT_DEC 2, a
xor rax, rax
ret
section .bss
a resw 1
곱하기
%include "io64.inc"
section .text
global CMAIN
CMAIN:
;write your code here
PRINT_DEC 2, ax
NEWLINE
mov ax, 0
mov al, 2
mov bl, 4
PRINT_DEC 1, bx
NEWLINE
mul bx
PRINT_DEC 1, ax
NEWLINE
xor rax, rax
ret
나누기
%include "io64.inc"
section .text
global CMAIN
CMAIN:
;write your code here
;7/2
mov ax, 7
mov bl, 2
div bl
mov bl, ah ; ah == 나머지값
PRINT_DEC 1, al
NEWLINE
PRINT_DEC 1, bl
NEWLINE
xor rax, rax
ret
곱하고 나누고
%include "io64.inc"
section .text
global CMAIN
CMAIN:
mov rbp, rsp; for correct debugging
;
mov ax, 0
mov al, 2
mov bl, 3
mul bx
PRINT_DEC 1, ax
NEWLINE
mov ax, 7
mov bl, 2
div bl
mov bl, ah
PRINT_DEC 1, al
NEWLINE
PRINT_DEC 1, bl
NEWLINE
xor rax, rax
ret
연습문제
2개의 변수를 사용자로부터 1byte단위로 입력받아 메모리에 저장하고 더하고, 빼고 , 곱하고 나눈값을 메모리에 각각 개별적으로 저장후 출력하라.
안돌아감... 틀린답.
고치는건 4일차에하자
%include "io64.io"
section .text
global CMAIN
CMAIN:
;write your code here
GET_DEC 1, al
GET_DEC 1, bl
mov [input_a], al
mov [input_b], bl
add al, bl
mov [result_add], al
PRINT_STRING msg_result_add
PRINT_DEC 1,result_add
NEWLINE
mov al, [input_a]
sub al, bl
mov [result_sub], al
PRINT_STRING msg_result_sub
PRINT_DEC 1, result_sub
NEWLINE
mov ax, 0
mov al, input_a
mul bl
mov [result_mul], ax
PRINT_STRING msg_result_mul
PRINT_DEC 2, result_mul
NEWLINE
mov ax, [input_a]
div bl
mov [result_div_quotient], al
mov [result_div_remainder], ah
PRINT_STRING msg_result_div
PRINT_STRING msg_open_bracket
PRINT_DEC 1, result_div_quotient
PRINT_STRING msg_slash
PRINT_DEC 1, result_div_remainder
PRINT_STRING msg_close_bracket
xor rax, rax
ret
section .bss
input_a resb 1
input_b resb 1
result_add resb 1
result_sub resb 1
result_mul resw 1
result_div_quotient resb 1
result_div_remainder resb 1
section .data
msg_result_add db 'add : ',0x00
msg_result_sub db 'sub : ',0x00
msg_result_mul db 'mul : ',0x00
msg_result_div db 'div[quotient/remainder] : ',0x00
msg_open_bracket db '[',0x00
msg_close_bracket db ']',0x00
msg_slash db '/',0x00