Skip to content

Instantly share code, notes, and snippets.

@dinosaurfiles-zz
Last active October 27, 2023 22:36
Show Gist options
  • Save dinosaurfiles-zz/de57c0d64414cca7562a to your computer and use it in GitHub Desktop.
Save dinosaurfiles-zz/de57c0d64414cca7562a to your computer and use it in GitHub Desktop.
[Assembly x86] Pseudo-Random Number Generator using Linear Congruential Generator (LCG) with Interfacing Assembly w/ C
%include "asm_io.inc"
segment .data
segment .bss
segment .text
global startgame
startgame:
enter 4,0 ; allocate room for sum on stack
mov [ebx], eax
call randomnumgenerator
call print_int
call print_nl
leave
ret
randomnumgenerator:
mov eax, [ebp+8]
mov edx, [ebp+12]
imul eax, edx
mov edx, [ebp+16]
add eax, edx
mov ecx, [ebp+20]
cdq
idiv ecx
mov eax, edx
cmp eax, dword 0
jg pos
neg eax
pos:
mov [ebp+8], eax
ret
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "cdecl.h"
void PRE_CDECL startgame (int, int, int, int, int) POST_CDECL;
void main () {
int i, seed, a, b, m = 26;
srand(time(0));
a = rand();
b = rand();
seed = rand();
startgame(seed, a, b, m, 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment