Question: Write a program to read two numbers and print the smaller one. Example run: Enter first number: 27 Enter second number: 10 Smaller = 10


Write a program to read two numbers and print the smaller one. Example run: Enter first number: 27 Enter second number: 10 Smaller = 10 Discussion: To read a number from the keyboard we use the author's routine, ReadDec. call ReadDec Input Numi mov numi, EAX To write a number to the screen we use the author's routine WriteDec. mov EAX, num ; Print numi call WriteDec ; if boolean-expression THEN/ENDIF cmp boolexp ; IF boolexp jnBop Labeli True Statement Labell: ; ENDIE Note: The boolexp (Boolean expression) would have a logical expression using the Boolean operators (> " then the op code would be "ing" or "jna". example cmp char, 19 jna labell ; IF char> 19 lea EDX, digGMsg Print "Not a valid digit" call WriteString label1: ; ENDIE Note: to be successful in writing the correct code, think about how the IF is supposed to work. In this example the print is executed if the condition is true. If it is false the jump is to the labell or the ENDIF. The JNA says to jump if the cmp does not give us an above results. ; if boolean-expressiont THEN/ELSE/ENDIF cmp boolexp ; IF boolexp ; jnBop = jump not Boolean operator jnBop Labell True Statement imp Labe12 Labell: ; ELSE False Statement Label2: : ENDIF ; example cmp digit, 5 jna labeli ; IF digit > 5 Print " digit > 5" lea EDX, digGMsg call WriteString jmp label2 labell: ; ELSE lea EDX, digNGMsg Print digit is Not > 5 call WriteString label2: ; ENDIF Note: if the cmp is false we jump to labe11 (ELSE). If it is true then we fall into the then and jump (JMP) over the ELSE The JMP is an unconditional jump. It is important when learning that you write code that makes sense to you. The following is another way to write the same thing. ja THEN jmp ELSE THEN: jmp ENDIE ELSE: ENDIF; Note: the "ja THEN" and "jmp ELSE" act the same as "jna ELSE". Solve the problem with pseudocode first. Output: Larger num Input: numi and num2 Processing: determine which is smaller Therefore, the pseudocode would be: 11 11 ; Start ; Print "Enter first number: ; Input num1 ; Print "Enter second number: ; Input num2 ; IF numl
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
