SHARE
TWEET

Untitled

a guest Nov 14th, 2019 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Table of Contents
  3. Stage 1 Compare Values  2
  4. Stage 2 Verifying Values    5
  5. Stage 3 Output Card Value (character or number) 9
  6. Pseudocode  13
  7.  
  8. Stage 1 Compare Values
  9.  
  10. 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.
  11.       //Stage 1 is all about comparing two values to see if an input is bigger than the other.
  12.       //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
  13.       MOV R2, #equaltostring
  14.       MOV R3, #lessthanstring
  15.       MOV R4, #greaterthanstring
  16.       //Allows for the input of two separate numbers which are stored in Register 0 and Register 1
  17.       INP R0, 2
  18.       INP R1, 2
  19.       //Compare the two inputs and uses the appropriate branching instruction
  20.       CMP R1, R0
  21.       BEQ equaltostring
  22.       BGT greaterthanstring
  23.       BLT lessthanstring
  24.       HALT
  25.  
  26.       //String to say, "Number two is equal to number one". Created using Hexadecimal
  27. equaltostring:
  28.       OUT r2, 8
  29.       dat 0x626d754e
  30.       dat 0x74207265
  31.       dat 0x69206f77
  32.       dat 0x71652073
  33.       dat 0x206c6175
  34.       dat 0x6e206f74
  35.       dat 0x65626d75
  36.       dat 0x6e6f2072
  37.       dat 0x0065
  38.       //String which says, "Number two is less than number one". Created using Hexadecimal
  39. lessthanstring:
  40.       out R3, 8
  41.       dat 0x626d754e
  42.       dat 0x74207265
  43.       dat 0x69206f77
  44.       dat 0x656c2073
  45.       dat 0x74207373
  46.       dat 0x206e6168
  47.       dat 0x626d756e
  48.       dat 0x6f207265
  49.       dat 0x656e
  50.       //String which says "Number two is greater than number one"
  51. greaterthanstring:
  52.       out R4, 8
  53.       dat 0x626d754e
  54.       dat 0x74207265
  55.       dat 0x69206f77
  56.       dat 0x72672073
  57.       dat 0x65746165
  58.       dat 0x68742072
  59.       dat 0x6e206e61
  60.       dat 0x65626d75
  61.       dat 0x6e6f2072
  62.       dat 0x65
  63. Stage 2 Verifying Values
  64.  
  65. 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.
  66.  
  67.       //Stage 2
  68.       //START
  69.       MOV R2, #equaltostring
  70.       MOV R3, #lessthanstring
  71.       MOV R4, #greaterthanstring
  72.       MOV R5, #13
  73.       MOV R6, #maximumvaluestring
  74.       MOV R7, #1
  75.       MOV R8, #minimumvaluestring
  76.       //Input 2 Numbers and validate whether each input is between 1-13
  77.       INP R0, 2
  78.       CMP R0, R5
  79.       BGT maximumvaluestring
  80.       CMP R0, R7
  81.       BLT minimumvaluestring
  82.       INP R1, 2
  83.       CMP R1, R5
  84.       BGT maximumvaluestring
  85.       CMP R1,R7
  86.       BLT minimumvaluestring
  87.       B compareinputs
  88.       //Compare the two inputs
  89. compareinputs:
  90.       CMP R1, R0
  91.       BEQ equaltostring
  92.       BGT greaterthanstring
  93.       BLT lessthanstring
  94.       HALT
  95.       //String which says, "Invalid Input!"
  96. minimumvaluestring:
  97.       out R6, 8
  98.       dat 0x61766e49
  99.       dat 0x2064696c
  100.       dat 0x75706e49
  101.       dat 0x0a74
  102.       HALT
  103.       //String which says, "Invalid Input!"
  104. maximumvaluestring:
  105.       out R8, 8
  106.       dat 0x61766e49
  107.       dat 0x2064696c
  108.       dat 0x75706e49
  109.       dat 0x0a74
  110.       HALT
  111.       //String which says "Number two is equal to number one"
  112. equaltostring:
  113.       OUT r2, 8
  114.       dat 0x626d754e
  115.       dat 0x74207265
  116.       dat 0x69206f77
  117.       dat 0x71652073
  118.       dat 0x206c6175
  119.       dat 0x6e206f74
  120.       dat 0x65626d75
  121.       dat 0x6e6f2072
  122.       dat 0x0065
  123.       //String which says "Number two is less than number one"
  124. lessthanstring:
  125.       out R3, 8
  126.       dat 0x626d754e
  127.       dat 0x74207265
  128.       dat 0x69206f77
  129.       dat 0x656c2073
  130.       dat 0x74207373
  131.       dat 0x206e6168
  132.       dat 0x626d756e
  133.       dat 0x6f207265
  134.       dat 0x656e
  135.       //String which says "Number two is greater than number one"
  136. greaterthanstring:
  137.       out R4, 8
  138.       dat 0x626d754e
  139.       dat 0x74207265
  140.       dat 0x69206f77
  141.       dat 0x72672073
  142.       dat 0x65746165
  143.       dat 0x68742072
  144.       dat 0x6e206e61
  145.       dat 0x65626d75
  146.       dat 0x6e6f2072
  147.       dat 0x65
  148. Stage 3 Output Card Value (character or number)
  149.  
  150. 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.
  151.       //Stage 1
  152.       //START – Move all strings and minimum and maximum values into free registers
  153.       MOV R2, #equaltostring
  154.       MOV R3, #lessthanstring
  155.       MOV R4, #greaterthanstring
  156.       MOV R5, #13
  157.       MOV R6, #maximumvaluestring
  158.       MOV R7, #1
  159.       MOV R8, #minimumvaluestring
  160.       //Input 2 Numbers and validate whether each input is between 1-13
  161.       INP R0, 2
  162.       CMP R0, R5
  163.       BGT maximumvaluestring
  164.       CMP R0, R7
  165.       BLT minimumvaluestring
  166.       INP R1, 2
  167.       CMP R1, R5
  168.       BGT maximumvaluestring
  169.       CMP R1,R7
  170.       BLT minimumvaluestring
  171.       B compareinputs
  172.       //Compare the two inputs
  173. compareinputs:
  174.       CMP R1, R0
  175.       BEQ equalsoutput
  176.       BGT greateroutput
  177.       BLT lessoutput
  178.       //Terminates the Program
  179. terminate:
  180.       HALT
  181.       //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
  182. equalsoutput:
  183.       LDR R9, [R0 + cardletters]
  184.       LDR R10, [R1 + cardletters]
  185.       MOV R2, #equaltostring
  186.       OUT R10, 7
  187.       OUT R2, 8
  188.       OUT R9, 7
  189.       b terminate
  190.       //Converts the numbers into the correct card values which are stored in "cardletters". This will be executed whenever num2 is greater than num1
  191. greateroutput:
  192.       LDR R9, [R0 + cardletters]
  193.       LDR R10, [R1 + cardletters]
  194.       MOV R2, #greaterthanstring
  195.       OUT R10, 7
  196.       OUT R2, 8
  197.       OUT R9, 7
  198.       b terminate
  199.       //Converts the numbers into the correct card values which are stored in "cardletters". This will be executed whenever num2 is less than num1
  200. lessoutput:
  201.       LDR R9, [R0 + cardletters]
  202.       LDR R10, [R1 + cardletters]
  203.       MOV R2, #lessthanstring
  204.       OUT R10, 7
  205.       OUT R2, 8
  206.       OUT R9, 7
  207.       b terminate
  208.       //Says "Invalid Input!" if the value is under 1
  209. minimumvaluestring:
  210.       out R6, 8
  211.       dat 0x61766e49
  212.       dat 0x2064696c
  213.       dat 0x75706e49
  214.       dat 0x0a74
  215.       b terminate
  216.       //Says "Invalid Input!" if the value is over 13
  217. maximumvaluestring:
  218.       out R8, 8
  219.       dat 0x61766e49
  220.       dat 0x2064696c
  221.       dat 0x75706e49
  222.       dat 0x0a74
  223.       b terminate
  224.       //Says " is EQUAL to "
  225. equaltostring:
  226.       OUT r2, 8
  227.       dat 0x20736920
  228.       dat 0x41555145
  229.       dat 0x6f74204c
  230.       dat 0x20
  231.       //Says "is LOWER than"
  232. lessthanstring:
  233.       out R3, 8
  234.       dat 0x4c207369
  235.       dat 0x5245574f
  236.       dat 0x61687420
  237.       dat 0x6e
  238.       //Says " is GREATER than "
  239. greaterthanstring:
  240.       out R4, 8
  241.       dat 0x20736920
  242.       dat 0x41455247
  243.       dat 0x20524554
  244.       dat 0x6e616874
  245.       dat 0x20
  246. cardletters:
  247.       // this is an array of all of the letters corresponding to the card values
  248.       dat 0x00 //NA
  249.       dat 0x41 // A
  250.       dat 0x32 // 2
  251.       dat 0x33 // 3
  252.       dat 0x34 // 4
  253.       dat 0x35 // 5
  254.       dat 0x36 // 6
  255.       dat 0x37 // 7
  256.       dat 0x38 // 8
  257.       dat 0x39 // 9
  258.       dat 0x3031 // 10
  259.       dat 0x4A // J
  260.       dat 0x51 // Q
  261.       dat 0x4B // K
  262.  
  263. Pseudocode
  264.  
  265. //START
  266. Move #equalstring into Register 02
  267. Move #lessthanstring into Register 03
  268. Move #greaterthanstring into Register 04
  269. Move Value of 13 in Register 05
  270. Move #maximumvaluestring into Register 06
  271. Move Value of 1 into Register 07
  272. Move #minimumvaluestring into Register 08
  273. //INPUT
  274. Ask for an input and store it in Register 0
  275. Compare Input stored in Register 0 to Value of 13 in Register 5
  276. Jump if Input is larger than 13 to maximumvaluestring
  277. Compare Input stored in Register 0 to value of 1 in Register 7
  278. Jump if Input is less than 1 to minimumvaluestring
  279.  
  280. Ask for Input and store it in Register 1
  281. Compare input stored in Register 1 with value of 13 in Register 5
  282. Jump if input is larger than 13 to maximumvaluestring
  283. Compare input stored in Register 0 to value of 1 in Register 7
  284. Jump if input Is less than 1 to minimumvaluestring
  285.  
  286. Jump to compareinputs if none are true
  287.  
  288.  
  289.  
  290. //COMPARE
  291. Compareinputs:
  292. Compare value stored in register 1 with value in register 0
  293. If Register 1 and Register 0 are equal then jump to equalsoutput
  294. If Register 1 and Register 0 are equal then jump to greateroutput
  295. If Register 1 and Register 0 are equal then jump to lessoutput
  296. //TERMINATE
  297. Terminate:
  298. HALT
  299.  
  300. //CONVERT NUMBERS TO LETTERS IF EQUAL
  301. Equalsoutput:
  302. Offset Input 1 stored in Register 2 to the array of cardletters and store in Register 9
  303. Offset Input 2 stored in Register 1 to the array of cardletters and store in Register 10
  304. Move equaltostring to Register 02
  305. Output Register 10 as a single ASCII character
  306. Output Register 2 as an ASCII string
  307. Output Register 9 as a single ASCII character
  308. Jump to terminate
  309.  
  310. //CONVERT NUMBERS TO LETTERS IF NUM2 IS GREATER THAN NUM1
  311. Offset Input 1 stored in Register 2 to the array of cardletters and store in Register 9
  312. Offset Input 2 stored in Register 1 to the array of cardletters and store in Register 10
  313. Move greatherthanstring to Register 02
  314. Output Register 10 as a single ASCII Character
  315. Output Register 02 as a ASCII string
  316. Output Register 09 as a single ASCII character
  317. Jump to terminate
  318.  
  319. //CONVERT NUMBERS TO LETTERS IF NUM2 IS LESS THAN NUM1
  320. Offset Input 1 stored in Register 2 to the array of cardletters and store in Register 9
  321. Offset Input 2 stored in Register 1 to the array of cardletters and store in Register 10
  322. Move lessthanstring to Register 02
  323. Output Register 10 as a single ASCII Character
  324. Output Register 02 as an ASCII string
  325. Output Register 09 as a single ASCII character
  326. Jump to terminate
  327. //MINIMUMSTRINGVALUE OUTPUT
  328. “Invalid_Input!”
  329. Output Register 6 as an ASCII string
  330. Jump to terminate
  331. //MAXIMUMVALUESTRING OUTPUT
  332. “Invalid_Input!”
  333. Output Register 8 as an ASCII string
  334. //ISEQUALTO OUTPUT
  335. “_is_EQUAL_to”
  336. Output Register 02 as an ASCII string
  337. //ISLOWERTHAN OUTPUT
  338. “_is_LOWER_than”
  339. Output Register 03 as an ASCII string
  340. “_is_GREATER_than”
  341. Output Register 4 as an ASCII string
  342. //ASCII CARD VALUES ARRAY
  343. Cardletters:
  344. ASCII VALUE of A
  345. ASCII VALUE of 2
  346. ASCII VALUE of 3
  347. ASCII VALUE of 4
  348. ASCII VALUE of 5
  349. ASCII VALUE of 6
  350. ASCII VALUE of 7
  351. ASCII VALUE of 8
  352. ASCII VALUE of 9
  353. ASCII VALUE of 10
  354. ASCII VALUE of J
  355. ASCII VALUE of Q
  356. ASCII VALUE of K
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top