Presentation is loading. Please wait.

Presentation is loading. Please wait.

Important Irvine Library Procedures Randomize Randomize –Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures.

Similar presentations


Presentation on theme: "Important Irvine Library Procedures Randomize Randomize –Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures."— Presentation transcript:

1 Important Irvine Library Procedures Randomize 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 –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.

2 RandomRange Produces a random integer within the range of 0 to (n-1) Produces a random integer within the range of 0 to (n-1) N is passed in the EAX register. N is passed in the EAX register. The random integer is returned in EAX. The random integer is returned in EAX.

3 How to choose a random number between 0 and 4999.data RandvalDWORD?.code Call Randomize Moveax, 5000 CallRandomRange Movrandval, eax

4 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. 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. black = 0 red = 4 gray = 8 lightRed = 12 blue = 1 magenta = 5 lightBlue = 9 lightMagenta = 13 green = 2 brown = 6 lightGreen = 10 yellow = 14 cyan = 3 lightGray = 7 lightCyan = 11 white = 15

5 SetTextColor Not available in Irvine16.inc Not available in Irvine16.inc –(only Irvine32.inc) The background color must by multiplied by 16 before being added to the foreground color. The background color must by multiplied by 16 before being added to the foreground color. Example Example –Moveax, yellow + (blue * 16) –CallSetTextColor;yellow on blue

6 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. 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: Inputs: –DH = Y-coordinate (row value) –DL = X-coordinate (column value)

7 ReadChar Reads a single character from standard input and returns the character in the AL register. The character is not echoed to the screen. Reads a single character from standard input and returns the character in the AL register. The character is not echoed to the screen.

8 Clrscr Clears the console and locates the cursor at the upper left corner. Clears the console and locates the cursor at the upper left corner.

9 Programming Assignment Programming Assignment 1) 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. 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.

10 Programming Assignment (cont) 2) 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.

11 What to turn in for the Programming Assignment Structure Chart or detailed outline Structure Chart or detailed outline Listing File Listing File Executable on Diskette Executable on Diskette


Download ppt "Important Irvine Library Procedures Randomize Randomize –Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures."

Similar presentations


Ads by Google