Advertisement

Generate number in range and compare it to user input

Started by April 10, 2019 03:30 AM
4 comments, last by Tom Sloper 5 years, 8 months ago

Hey everyone, i'm new in assembly 32 bits. I would like to know how can i generate a random number in range 0 - 255 in assembly 32 bits (Linux). I already implemented a code :


segment .data
 
msg:		db "Enter number between 255 et 0 :"
len:		equ $-msg
nom_fic:	db "/dev/urandom", 0	
	
segment .bss
choice:	resb 17			;
len_choice:	resb 1
buffer:	dd 0

segment .text
	global _start		; 
_start:

	mov eax, 5		; open file
	mov ebx, nom_fic	;file name
	mov ecx, 0		; options
	int 0x80		; 
        push eax 		;

	mov eax, 3
	pop eax			; 
	mov ebx, eax		;
	mov ecx, buffer
	mov ebx,1
	int 0x80


	
		

	mov eax, 4
	mov ebx, 0
	mov ecx, msg
	mov edx, len
	int 0x80

	mov eax, 4
	mov ebx, 0
	mov ecx, buffer
	mov edx, 1
	int 0x80

	mov eax, 6		
	int 0x80

	mov ebx, 0		; 
	mov eax, 1		;  
	int 0x80		; 

As i said, i'm only a beginner, i can't translate what i want into a code, so please implement a code. Thank you so much !

Is this home work?

Any way, find a pseudo random number generator algorithm and implement it. The simplest are quite simple in assembly language.

Advertisement

Seems like a pretty popular thing using these google search terms

psudo ranged random asm

https://www.google.com/search?q=psudo+ranged+random+asm&oq=psudo+ranged+random+asm

15 hours ago, Neo C said:

 <snip>  i can't translate what i want into a code, so please implement a code. </snip>

I don't understand this part. What do you mean?

Dev careful. Pixel on board.

I mean that i can't translate what i want to do into a code.

Yes  this a homework

I found a function that return generate the number, thanks for u help

5 hours ago, Neo C said:

Yes  this a homework

We don't help with homework here. Talk to your professor and your fellow students.

Locking thread.

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement