120 likes | 417 Views
Important Irvine Library Procedures. Randomize Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures. The seed equals the time of day, accurate to 1/100 th of a second. Only call it once at the beginning of a program
E N D
Important Irvine Library Procedures • Randomize • Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures. • The seed equals the time of day, accurate to 1/100th of a second. • Only call it once at the beginning of a program • This ensures that each time you run a program, the starting random integer will be different, and any sequence of random integers will also be unique.
RandomRange • Produces a random integer within the range of 0 to (n-1) • N is passed in the EAX register. • The random integer is returned in EAX.
How to choose a random number between 0 and 4999 .data Randval DWORD ? .code Call Randomize Mov eax, 5000 Call RandomRange Mov randval, eax
SetTextColor • Sets the current foreground and background colors for text output. The color constants are predefined and can be used for both the foreground and background.
SetTextColor • Not available in Irvine16.inc • (only Irvine32.inc) • The background color must by multiplied by 16 before being added to the foreground color. • Example • Mov eax, yellow + (blue * 16) • Call SetTextColor ;yellow on blue
GoToXY • Locates the cursor at a given row and column on the screen. Using a console screen, the x-coordinate range is 0-79, and the y-coordinate range is 0-24. • Inputs: • DH = Y-coordinate (row value) • DL = X-coordinate (column value)
ReadChar • Reads a single character from standard input and returns the character in the AL register. The character is not echoed to the screen.
Clrscr • Clears the console and locates the cursor at the upper left corner.
Programming Assignment • Draw Text Colors Write a program that clears the screen, generates and displays 50 random numbers (0-9), in 50 random colors (only use the 16 different colors available to you, but call the random number generator each time a number is generated). Use the Irvine library functions (Randomize, RandomRange, and SetTextColors) to generate and display the results. Wait for a keyboard input before exitting the program. You may use the library function (Readchar, ReadInt, or ReadString) to read the character.
Programming Assignment (cont) • In class, we discussed the evaluation of the expression (-3)*VALUE using only shifts, adds and subtracts. Will this same code work to evaluate the expression (+5)*VALUE? If not, create a program to implement this. Will this same code work to evaluate the expression (-5)*VALUE? If not, add this to your program. Display on the screen a message allowing the user to input an 8-bit input(values between 0 and 255, evaluate each of the above expressions and display 16-bit results in binary, hex and in decimal. You do not have to provide error checking for the input data. You may use the Irvine library functions for I/O.
What to turn in for the Programming Assignment • Structure Chart or detailed outline • Listing File • Executable on Diskette