Assignment 7: Random Number Generation and Procedures in MASM

Verified

Added on  2022/08/24

|5
|468
|16
Homework Assignment
AI Summary
This assignment presents two solutions for generating random numbers using Assembly Language (MASM). The first solution, 'Assignment7, Version 1,' generates random numbers within a predefined range. The second solution, 'Assignment7, Version 2,' expands on this by allowing the user to define the upper and lower bounds for the random number generation, providing a more dynamic and interactive approach. Both solutions utilize the Irvine32 library and demonstrate the use of procedures, demonstrating how to work with random number generation in assembly language. The assignment also includes a basic bibliography with relevant sources, including those focused on modern X86 Assembly Language Programming, and applications in diverse fields such as 3D printing, and edge artificial intelligence.
Document Page
Running head: COMPUTER SCIENCE
Computer science
Name of the Student
Name of the University
Author’s Note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1
COMPUTER SCIENCE
Part 1: Better Random Range Procedure
Title Assignment7, Version 1 (Assignment7.asm)
; This program prints random number
INCLUDE Irvine32.inc
.data
.code
main PROC
call Clrscr
mov eax, -300
mov ebx, 100
mov ecx, 50
L1:
push eax ; range doesnot changes
push ebx
call BetterRandomRange
pop ebx
pop eax
Loop L1
call WaitMsg
exit
main ENDP
BetterRandomRange PROC
sub ebx, eax ;mov 400 to ebx
xchg ebx, eax ;random works with eax
call RandomRange ; generate random int
neg ebx
sub eax, ebx ;sub 300 from eax to define range
call WriteInt ; write signed decimal
call Crlf
ret
BetterRandomRange ENDP
END main
Document Page
2
COMPUTER SCIENCE
Part 2: Better Random Range Procedure with prompt message
Title Assignment7, Version 2 (Assignment7.asm)
; This program prints random number
INCLUDE Irvine32.inc
.data
prompt_1 BYTE "Enter the upper bound : ", 0
value_1 DWORD ?
prompt_2 BYTE "Enter the lower bound : ", 0
value_2 DWORD ?
.code
main PROC
; Get user value 1
mov edx, OFFSET prompt_1
call writestring
call readint
mov value_1,eax
call crlf
; Get user value 2
mov edx, OFFSET prompt_2
call writestring
call readint
mov value_2, eax
call crlf
mov eax, 0
mov eax, value_1
mov ebx, value_2
mov ecx, 30
L2:
push eax ; doesn't change range
push ebx
call BetterRandomRange
pop ebx
pop eax
Loop L2
call WaitMsg
exit
main ENDP
BetterRandomRange PROC
sub ebx, eax ;mov 400 to ebx
xchg ebx, eax ;random works with eax
call RandomRange ; generate random int
neg ebx
sub eax, ebx ;sub 300 from eax to define range
call WriteInt ; write signed decimal
Document Page
3
COMPUTER SCIENCE
call Crlf
ret
BetterRandomRange ENDP
Random3 proc
mov ax, 3
call main
call BetterRandomRange
add ax, 1
ret
Random3 endp
END main
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4
COMPUTER SCIENCE
Bibliography
Kusswurm, D., 2018. Modern X86 Assembly Language Programming: Covers X86 64-bit, AVX,
AVX2, and AVX-512. Apress.
Qi, S., Guo, H., Fu, J., Xie, Y., Zhu, M. and Yu, M., 2020. 3D printed shape-programmable
magneto-active soft matter for biomimetic applications. Composites Science and
Technology, 188, p.107973.
Zhang, W., Zhang, Z., Zeadally, S., Chao, H.C. and Leung, V.C., 2019. MASM: A multiple-
algorithm service model for energy-delay optimization in edge artificial intelligence. IEEE
Transactions on Industrial Informatics, 15(7), pp.4216-4224.
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]