%include "CONSTANTS.h" SYS_GETRANDOM equ 318 SIDES equ 20 TRIALS equ 1000000 section .data rollResult: dq 0 fmt: db `%d occured %d times\n`,0 section .bss counts: resq SIDES section .text global main main: ; for(int i = 0; i < TRIALS; ++I) { ; use r12 for i mov r12, 0 GenLoopTop: cmp r12, TRIALS jge .done ; roll = rand() % SIDES mov rax, SYS_GETRANDOM mov rdi, rollResult mov rsi, 4 mov rdx, 0 syscall ; counts[roll]++ mov rdx, 0 mov rax, [rollResult] mov r8, SIDES div r8 ; rax = [rollResult]/ SIDES ; rdx = [rollResult] % SIDES inc qword [counts + rdx * 8] ; base address + index * size of element + offset into structure ;} inc r12 jmp GenLoopTop .done: ; print it out ; for(int i = 0; i < sides; ++i) ; cout << i << "occured " sides[i] << " times " << endl; mov r12, 0 PrintLoopTop: cmp r12, SIDES jge .done mov rdi, fmt mov rsi, r12 mov rdx, [counts + r12*8] call CallPrintf inc r12 jmp PrintLoopTop .done: jmp Exit