0
;  Chapter 6 Program

; Programmed in MASM on April 17th
; Replaced .ENDIF, and .ELSEIF directives with cmp and jump statements

INCLUDE Irvine32.inc

.data
  TRUE = 1
  FALSE = 0
  gradeAverage  DWORD ?   ; grade average
  credits       DWORD ?   ; amount of credits
  OkToRegister  BYTE ?
  prompt2 BYTE "Enter the amount of credits ",0
  prompt3 BYTE "Enter grade average ",0
  prompt4 BYTE "Credit's cannot be less than 1  or greater than 30, Please enter a valid amount of credits: ",0
  prompt5 BYTE "The student can register ",0
  prompt6 BYTE "The student cannot register ",0

.code
main PROC
  mov OkToRegister,FALSE
  mov edx,OFFSET prompt3
  call WriteString
  call ReadInt
  mov gradeAverage,eax
  mov edx,OFFSET prompt2
  call WriteString
  call ReadInt
  mov credits,eax
  cmp credits,30
  ja toomany
  cmp credits,1
  jbe toomany
  cmp credits,1
  ja good
  toomany:call crediterror
  good:
  cmp gradeAverage,350
  jbe Larger
  mov OkToRegister,TRUE
  jmp register1
  Larger:
  cmp gradeAverage,250
  jbe ppp
  cmp credits,16
  ja ppp
  mov OkToRegister,TRUE
  jmp register1
  ppp:
  cmp credits,12
  ja register1
  mov OkToRegister,TRUE
  cmp OkToRegister,1
  JE register1
  cmp OkToRegister,0
  JE cregister1
  cregister1:
  call cregister
  register1:
  call register
  exit
main ENDP

crediterror proc
  mov edx,OFFSET prompt4
  call WriteString
  call ReadInt
  mov credits,eax
  ret
  crediterror ENDP

register proc
mov edx,OFFSET prompt5
  call WriteString
  ret
  register ENDP

cregister proc
  mov edx,OFFSET prompt6
  call WriteString
  ret
  cregister ENDP

END main

Instead of displaying one or the other it displays both.

Here is the assignment for the program:

Using the College Registration example from Section 7.3 as a starting point, do the following:

Recode the logic using CMP and conditional jump instructions (instead of the .IF and .ELSEIF directives).

Perform range checking on the credits value; it cannot be less than 1 or greater than 30. If an invalid entry is discovered, display an appropriate error message.

Prompt the user for the grade average and credits values.

Display a message that shows the outcome of the evaluation, such as "The student can register" or "The student cannot register".

The Irvine32 library is required for this solution program.

Community
  • 1
  • 1
  • Your code is an unreadable mess with everything on the left column. Indent code one tab to the right of labels, and leave a blank line between separate blocks of logic. Most likely you forgot to `jmp` over the `else` case in an if/else type of logic, so execution fell through from one print to the other. Or you forgot to `ret` at the end of your functions. `foo endp` doesn't emit a `ret` instruction for you. *Use a debugger to single step your code.* – Peter Cordes Apr 17 '20 at 16:58
  • I'm sorry man, you were right I forgot to ret. I'm not very good at programming and learning programming through zoom has been chaos for me. I will spend this entire summer becoming better. – Johnathan B Apr 17 '20 at 17:13
  • The main thing I can recommend is *use a debugger*. Just looking at the output doesn't tell you nearly as much as single-stepping a line at a time. You'd see execution fall off the end of one function, into the next. Debugging without a debugger is like trying to build a robot blindfolded. Visual Studio has a decent one built in. – Peter Cordes Apr 17 '20 at 17:23

0 Answers0