Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Table of Contents
- Stage 1 Compare Values 2
- Stage 2 Verifying Values 5
- Stage 3 Output Card Value (character or number) 9
- Pseudocode 13
- Stage 1 Compare Values
- Below is all the code that I am utilizing to allow me to compare two separate values for stage 1. Everything is working correctly. At the start of my Program within my START block I am moving the three strings into REGISTER 2, 3 and 4 to allow me to call them during the run time of the program. Next I allow the user to use the input device to input two separate numbers by using INP R0,2 and INP R1,2. I am storing the users input in Register 1 and 2 and they will be stored there throughout the entire runtime. I have created three separate strings in my program which are results of the comparison to output if number two is bigger, smaller or equal to number one. To compare the values, I use CMP R1, R0 which compares Register1(num2) to Register0(num1) and runs the appropriate instruction. If the numbers are equal BEQ (branch if equal) equaltostring is used to output a message saying, “Number two is equal to number one”. If the number 2 is less than number 1 BLT (branch if less than) lessthanstring is used to output a message saying, “Number 2 is less than number 1”. If number 2 is more than number 1 BGT (branch if greater than) greaterthanstring is used to display a message saying, “Number 2 is greater than number 1”. To create the strings, I used the instruction DAT to put hexadecimal directly into memory.
- //Stage 1 is all about comparing two values to see if an input is bigger than the other.
- //START – In this block I am moving all the strings into a register to allow them to be called later during the execution of the program if needed
- MOV R2, #equaltostring
- MOV R3, #lessthanstring
- MOV R4, #greaterthanstring
- //Allows for the input of two separate numbers which are stored in Register 0 and Register 1
- INP R0, 2
- INP R1, 2
- //Compare the two inputs and uses the appropriate branching instruction
- CMP R1, R0
- BEQ equaltostring
- BGT greaterthanstring
- BLT lessthanstring
- HALT
- //String to say, "Number two is equal to number one". Created using Hexadecimal
- equaltostring:
- OUT r2, 8
- dat 0x626d754e
- dat 0x74207265
- dat 0x69206f77
- dat 0x71652073
- dat 0x206c6175
- dat 0x6e206f74
- dat 0x65626d75
- dat 0x6e6f2072
- dat 0x0065
- //String which says, "Number two is less than number one". Created using Hexadecimal
- lessthanstring:
- out R3, 8
- dat 0x626d754e
- dat 0x74207265
- dat 0x69206f77
- dat 0x656c2073
- dat 0x74207373
- dat 0x206e6168
- dat 0x626d756e
- dat 0x6f207265
- dat 0x656e
- //String which says "Number two is greater than number one"
- greaterthanstring:
- out R4, 8
- dat 0x626d754e
- dat 0x74207265
- dat 0x69206f77
- dat 0x72672073
- dat 0x65746165
- dat 0x68742072
- dat 0x6e206e61
- dat 0x65626d75
- dat 0x6e6f2072
- dat 0x65
- Stage 2 Verifying Values
- For Section 2 my code is fully functional and verifies the values without any issues. In this Section I start by moving all the strings into a register to allow them to be called later during the execution of the program if needed. I am also Moving the values of 13 and 1 into Registers 5 and 7 to allow me to compare the input to them later in the execution. To actually verify that the values are acceptable and are enough for the amounts of cards I firstly compare the first input(R0) to the value of R5(13), I use BGT(branch if greater than) maximumvaluestring to display a message saying “invalid input” if the user enters a valid over 13, the program will also get terminated. I also do this to ensure that the user does not enter a number below one by comparing the first input(R0) to R7(1). If the user enters a number less than one BLT (Branch if less than) minimumvaluestring will be ran displaying the message “invalid number” and terminating the program. This is also the same for the second input.
- //Stage 2
- //START
- MOV R2, #equaltostring
- MOV R3, #lessthanstring
- MOV R4, #greaterthanstring
- MOV R5, #13
- MOV R6, #maximumvaluestring
- MOV R7, #1
- MOV R8, #minimumvaluestring
- //Input 2 Numbers and validate whether each input is between 1-13
- INP R0, 2
- CMP R0, R5
- BGT maximumvaluestring
- CMP R0, R7
- BLT minimumvaluestring
- INP R1, 2
- CMP R1, R5
- BGT maximumvaluestring
- CMP R1,R7
- BLT minimumvaluestring
- B compareinputs
- //Compare the two inputs
- compareinputs:
- CMP R1, R0
- BEQ equaltostring
- BGT greaterthanstring
- BLT lessthanstring
- HALT
- //String which says, "Invalid Input!"
- minimumvaluestring:
- out R6, 8
- dat 0x61766e49
- dat 0x2064696c
- dat 0x75706e49
- dat 0x0a74
- HALT
- //String which says, "Invalid Input!"
- maximumvaluestring:
- out R8, 8
- dat 0x61766e49
- dat 0x2064696c
- dat 0x75706e49
- dat 0x0a74
- HALT
- //String which says "Number two is equal to number one"
- equaltostring:
- OUT r2, 8
- dat 0x626d754e
- dat 0x74207265
- dat 0x69206f77
- dat 0x71652073
- dat 0x206c6175
- dat 0x6e206f74
- dat 0x65626d75
- dat 0x6e6f2072
- dat 0x0065
- //String which says "Number two is less than number one"
- lessthanstring:
- out R3, 8
- dat 0x626d754e
- dat 0x74207265
- dat 0x69206f77
- dat 0x656c2073
- dat 0x74207373
- dat 0x206e6168
- dat 0x626d756e
- dat 0x6f207265
- dat 0x656e
- //String which says "Number two is greater than number one"
- greaterthanstring:
- out R4, 8
- dat 0x626d754e
- dat 0x74207265
- dat 0x69206f77
- dat 0x72672073
- dat 0x65746165
- dat 0x68742072
- dat 0x6e206e61
- dat 0x65626d75
- dat 0x6e6f2072
- dat 0x65
- Stage 3 Output Card Value (character or number)
- My Code is fully functional for this stage and displays the corresponding ASCII characters. Stage 3 is very similar to the previous two stages however it includes a feature that allows the program to convert the users input of numbers and convert them into ASCII Characters. This is done by utilizing an array and indexing. The array has set values that represent a deck of cards from A for Ace to K for King and everything else. The conversion is achieved through indexing which is very simple. In my code you can see that I have created three different outputs which are equalsoutput, greateroutput and lessoutput. These three different outputs all output different things however all utilize indexing to get the ASCII values of the numbers. They all start with LDR R9, [R0 + cardletters] which means the user input stored in R0 for example 3, it will jump three rows down the array and find the corresponding ASCII character in HEX and return the output and store it in Register 09. For example, entering 13 will jump down the array 13 times and land at the ASCII character of ‘K’ and store it within Register 09. This is also performed for Input 2 and is stored within Register 10. The output for this is slightly different as well as I have changed all the outcomes to “Is EQUAL to”, “is GREATER than” and “is LESS than”. If card number two was less than card one it would display a message by firstly Outputting Register10 as a single ASCII Character, then displaying the “is LESS than” ASCII STRING and finally displaying the first number stored in Register09. It is basically the same for the other two outcomes other than that it is a different message. My Pseudo also represents the program in its entirety.
- //Stage 1
- //START – Move all strings and minimum and maximum values into free registers
- MOV R2, #equaltostring
- MOV R3, #lessthanstring
- MOV R4, #greaterthanstring
- MOV R5, #13
- MOV R6, #maximumvaluestring
- MOV R7, #1
- MOV R8, #minimumvaluestring
- //Input 2 Numbers and validate whether each input is between 1-13
- INP R0, 2
- CMP R0, R5
- BGT maximumvaluestring
- CMP R0, R7
- BLT minimumvaluestring
- INP R1, 2
- CMP R1, R5
- BGT maximumvaluestring
- CMP R1,R7
- BLT minimumvaluestring
- B compareinputs
- //Compare the two inputs
- compareinputs:
- CMP R1, R0
- BEQ equalsoutput
- BGT greateroutput
- BLT lessoutput
- //Terminates the Program
- terminate:
- HALT
- //Converts the numbers into the correct card values which are stored in "cardletters". This will be executed if both cards are equal to one another
- equalsoutput:
- LDR R9, [R0 + cardletters]
- LDR R10, [R1 + cardletters]
- MOV R2, #equaltostring
- OUT R10, 7
- OUT R2, 8
- OUT R9, 7
- b terminate
- //Converts the numbers into the correct card values which are stored in "cardletters". This will be executed whenever num2 is greater than num1
- greateroutput:
- LDR R9, [R0 + cardletters]
- LDR R10, [R1 + cardletters]
- MOV R2, #greaterthanstring
- OUT R10, 7
- OUT R2, 8
- OUT R9, 7
- b terminate
- //Converts the numbers into the correct card values which are stored in "cardletters". This will be executed whenever num2 is less than num1
- lessoutput:
- LDR R9, [R0 + cardletters]
- LDR R10, [R1 + cardletters]
- MOV R2, #lessthanstring
- OUT R10, 7
- OUT R2, 8
- OUT R9, 7
- b terminate
- //Says "Invalid Input!" if the value is under 1
- minimumvaluestring:
- out R6, 8
- dat 0x61766e49
- dat 0x2064696c
- dat 0x75706e49
- dat 0x0a74
- b terminate
- //Says "Invalid Input!" if the value is over 13
- maximumvaluestring:
- out R8, 8
- dat 0x61766e49
- dat 0x2064696c
- dat 0x75706e49
- dat 0x0a74
- b terminate
- //Says " is EQUAL to "
- equaltostring:
- OUT r2, 8
- dat 0x20736920
- dat 0x41555145
- dat 0x6f74204c
- dat 0x20
- //Says "is LOWER than"
- lessthanstring:
- out R3, 8
- dat 0x4c207369
- dat 0x5245574f
- dat 0x61687420
- dat 0x6e
- //Says " is GREATER than "
- greaterthanstring:
- out R4, 8
- dat 0x20736920
- dat 0x41455247
- dat 0x20524554
- dat 0x6e616874
- dat 0x20
- cardletters:
- // this is an array of all of the letters corresponding to the card values
- dat 0x00 //NA
- dat 0x41 // A
- dat 0x32 // 2
- dat 0x33 // 3
- dat 0x34 // 4
- dat 0x35 // 5
- dat 0x36 // 6
- dat 0x37 // 7
- dat 0x38 // 8
- dat 0x39 // 9
- dat 0x3031 // 10
- dat 0x4A // J
- dat 0x51 // Q
- dat 0x4B // K
- Pseudocode
- //START
- Move #equalstring into Register 02
- Move #lessthanstring into Register 03
- Move #greaterthanstring into Register 04
- Move Value of 13 in Register 05
- Move #maximumvaluestring into Register 06
- Move Value of 1 into Register 07
- Move #minimumvaluestring into Register 08
- //INPUT
- Ask for an input and store it in Register 0
- Compare Input stored in Register 0 to Value of 13 in Register 5
- Jump if Input is larger than 13 to maximumvaluestring
- Compare Input stored in Register 0 to value of 1 in Register 7
- Jump if Input is less than 1 to minimumvaluestring
- Ask for Input and store it in Register 1
- Compare input stored in Register 1 with value of 13 in Register 5
- Jump if input is larger than 13 to maximumvaluestring
- Compare input stored in Register 0 to value of 1 in Register 7
- Jump if input Is less than 1 to minimumvaluestring
- Jump to compareinputs if none are true
- //COMPARE
- Compareinputs:
- Compare value stored in register 1 with value in register 0
- If Register 1 and Register 0 are equal then jump to equalsoutput
- If Register 1 and Register 0 are equal then jump to greateroutput
- If Register 1 and Register 0 are equal then jump to lessoutput
- //TERMINATE
- Terminate:
- HALT
- //CONVERT NUMBERS TO LETTERS IF EQUAL
- Equalsoutput:
- Offset Input 1 stored in Register 2 to the array of cardletters and store in Register 9
- Offset Input 2 stored in Register 1 to the array of cardletters and store in Register 10
- Move equaltostring to Register 02
- Output Register 10 as a single ASCII character
- Output Register 2 as an ASCII string
- Output Register 9 as a single ASCII character
- Jump to terminate
- //CONVERT NUMBERS TO LETTERS IF NUM2 IS GREATER THAN NUM1
- Offset Input 1 stored in Register 2 to the array of cardletters and store in Register 9
- Offset Input 2 stored in Register 1 to the array of cardletters and store in Register 10
- Move greatherthanstring to Register 02
- Output Register 10 as a single ASCII Character
- Output Register 02 as a ASCII string
- Output Register 09 as a single ASCII character
- Jump to terminate
- //CONVERT NUMBERS TO LETTERS IF NUM2 IS LESS THAN NUM1
- Offset Input 1 stored in Register 2 to the array of cardletters and store in Register 9
- Offset Input 2 stored in Register 1 to the array of cardletters and store in Register 10
- Move lessthanstring to Register 02
- Output Register 10 as a single ASCII Character
- Output Register 02 as an ASCII string
- Output Register 09 as a single ASCII character
- Jump to terminate
- //MINIMUMSTRINGVALUE OUTPUT
- “Invalid_Input!”
- Output Register 6 as an ASCII string
- Jump to terminate
- //MAXIMUMVALUESTRING OUTPUT
- “Invalid_Input!”
- Output Register 8 as an ASCII string
- //ISEQUALTO OUTPUT
- “_is_EQUAL_to”
- Output Register 02 as an ASCII string
- //ISLOWERTHAN OUTPUT
- “_is_LOWER_than”
- Output Register 03 as an ASCII string
- “_is_GREATER_than”
- Output Register 4 as an ASCII string
- //ASCII CARD VALUES ARRAY
- Cardletters:
- ASCII VALUE of A
- ASCII VALUE of 2
- ASCII VALUE of 3
- ASCII VALUE of 4
- ASCII VALUE of 5
- ASCII VALUE of 6
- ASCII VALUE of 7
- ASCII VALUE of 8
- ASCII VALUE of 9
- ASCII VALUE of 10
- ASCII VALUE of J
- ASCII VALUE of Q
- ASCII VALUE of K
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement