sfl-examples/slide-examples/assembly/ex09.asm

41 lines
1.4 KiB
NASM
Raw Normal View History

2023-12-14 14:12:51 +01:00
bits 64
SECTION .data
; empty
SECTION .text
global _start
_start:
%include "header.asm.inc"
; division: 17 / 4 (in 64-bit)
mov rcx, 4 ; divisor
mov rax, 17 ; dividend (LSB)
mov rdx, 0 ; dividend (MSB)
div cl ; 8-bit divisor, dividend is in AX
; ---> al = 4 (quotient), ah = 1 (remainder)
mov rax, 17 ; dividend (LSB)
mov rdx, 0 ; dividend (MSB)
div cx ; 16-bit divisor, dividend is in DX:AX
; ---> ax = 4 (quotient), dx = 1 (remainder)
mov rax, 17 ; dividend (LSB)
mov rdx, 0 ; dividend (MSB)
div ecx ; 32-bit divisor, dividend is in EDX:EAX
; ---> eax = 4 (quotient), edx = 1 (remainder)
mov rax, 17 ; dividend (LSB)
mov rdx, 0 ; dividend (MSB)
div rcx ; 64-bit divisor, dividend is in RDX:RAX
; ---> rax = 4 (quotient), rdx = 1 (remainder)
; challenge: 254 % 16
mov rcx, 16 ; divisor (64-bit)
mov rax, 0xfe ; dividend (LSB)
mov rdx, 0 ; dividend (MSB)
div rcx ; ---> rax = 15 (quotient), rdx = 14 (remainder)
%include "sysexit.asm.inc"