# Purpose: Practice using XOR, random #------------------------------------------------------------------- # The left c

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

# Purpose: Practice using XOR, random #------------------------------------------------------------------- # The left c

Post by answerhappygod »

# Purpose: Practice using XOR, random
#-------------------------------------------------------------------

# The left column is random keys depressed on a keyboard.
# A zero means the key is not pressed, a one means the key is
pressed.
# You need to determine the CHANGES from one left-hand row to the
next.
# PREVIOUS ==> 0
1 1
0
# NEW ==> 0
1 0
1
# MEANING ==> No Key
Still Key
New Key
# Change
Pressed Released
Depressed
# If a New Key is depressed, that bit should apprear on the
Right.
#-------------------------------------------------------------------

# SAMPLE OUTPUT:
# 00000000000000000000000001101011
00000000000000000000000001101011
# 00000000000000000000000000100111
00000000000000000000000000000100
# 00000000000000000000000000110001
00000000000000000000000000010000
# 00000000000000000000000011011111
00000000000000000000000011001110
# 00000000000000000000000011001001
00000000000000000000000000000000
# 00000000000000000000000010101100
00000000000000000000000000100100
# 00000000000000000000000010000111
00000000000000000000000000000011
# 00000000000000000000000010001001
00000000000000000000000000001000
# 00000000000000000000000011001011
00000000000000000000000001000010
# 00000000000000000000000010110110
00000000000000000000000000110100
# 00000000000000000000000011100111
00000000000000000000000001000001
# 00000000000000000000000011110110
00000000000000000000000000010000
# 00000000000000000000000001001000
00000000000000000000000000001000
# 00000000000000000000000001101011
00000000000000000000000000100011
# 00000000000000000000000000011010
00000000000000000000000000010000
# 00000000000000000000000011001101
00000000000000000000000011000101
.data
.eqv SYS_PRINT_WORD 1
#word, byte, character
.eqv SYS_PRINT_FLOAT 2
#float
.eqv SYS_PRINT_DOUBLE 3
#double
.eqv SYS_PRINT_TEXT 4 #text
(zero terminated)
.eqv SYS_EXIT
10 #terminate
.eqv SYS_PRINT_CHAR 11
#print char
.eqv SYS_READ_CHAR 12 #read
char
.eqv SYS_TIME
30 #system time to a1,a0
.eqv SYS_SLEEP 32
#delay a0 msec
.eqv SYS_PRINT_BIN 35
#print binary
.eqv SYS_SET_SEED 40
#set random seed
.eqv SYS_RAND_INT 42
#get random int

wait: .word 1000
#1 second
max: .word 16
#max loops
tab: .asciiz "\t"
endl: .asciiz "\n"
last: .word 0
#last random
.text
.globl main
main:
# get system time
li $v0, SYS_TIME
#get system time
syscall
# use system time lsb for seed a1, a0=0 for id
move $a1, $a0
#time lsw will be seed
li $a0, 0
#generator id 0
li $v0, SYS_SET_SEED
syscall
# initialize main loop: s7=max, s6=0 (loop
counter)
# main loop
loop:
# pause 'wait' msec using SYS_SLEEP
# get random integer in a0
# load 'last' into s0
# zero top 24 bits of a0 random
# save a0 new random lsb into 'last' and move a0
into s1
# print a0 random lsb as binary
# print a tab
# XOR s0 'last' with s1 new random lsb, save in a
register
# AND the XOR results with s1 new random lsb,
print as binary
# print a new line
# end loop: s6++, if s6==s7 then branch to
exit:
# else branch to
loop:
#------------------------
# terminate program.
exit:
li $v0, SYS_EXIT # call code for
terminate
syscall #
system call
#.end main
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply