title: College Fee Calculator Assembly(HLA) program
body: <p>I am writing in assembly, technically HLA(High Level Assembly) and am having trouble with an assignment. Here is the assignment: </p>
  
  <p><br/>Write an HLA Assembly language program that calculates student enrollment fees at Santa Monica College. (Since we only know how to deal with integer arithmetic, our program will be slightly inaccurate). As of Fall 2014, the enrollment fee is $46/unit for residents and $335/unit for all others. The student services fee is $48 for Winter or Summer and $51 for Fall or Spring. The puchase of a parking decal is optional which costs $85 in Fall/Spring or $45 in Winter/Summer.</p>
  
  <p>The enrollment fee will be entered based on a single 8-bit value entered by the user. The fee will have the format: prsseeee, where ss is a two-bit value corresponding to the semester (00 for Fall, 01 for Winter, 10 for Spring or 11 for Summer), eeee is a four-bit value corresponding to the number of enrolled units, r is a single bit corresponding to whether the student is a California resident or not and p is a single bit corresponding to whether a parking decal is desired. The format of this bit field is diagrammed below:</p>
  
  <p>Packed Bit Field of Fees
  Since just 8 bits are being entered, your program should expect to read 2 hexidecimal digits.</p>
  
  <p>Below are some sample program dialogues that demonstrate these ideas.
  (Hint: Do this in small steps, bit-by-bit. There's alot to it... )
  (Further Hint: The most important part of this assignment is to worked with the packed data field entered by the user to extract the sub-parts out of it. The overlapping design of the Intel registers helps you parse this kind of data field and you can shift the bits around to get the right part into BH or BL, for example... )
  (Further Hint: You can read hex numbers by reading directly into a register.)
  (Final Hint: Since we haven't learned how to do multiplication yet, although it's kinda painful, I was expecting that you would perform the multiplication by a looping set of addition instructions)</p>
  
  <p>Feed me(2 hex digits with the bits prsseeee): CC
  <br/>Fall Semester
  <br/>12 units
  <br/>CA Resident
  <br/>Parking
  <br/>Total Fees = $ 688</p>
  
  <p>Feed me(2 hex digits with the bits prsseeee): 4C
  <br/>Fall Semester
  <br/>12 units
  <br/>CA Resident
  <br/>No Parking
  <br/>Total Fees = $ 603</p>
  
  <p>Feed me(2 hex digits with the bits prsseeee): 8C
  <br/>Fall Semester
  <br/>12 units
  <br/>Non-Resident
  <br/>Parking
  <br/>Total Fees = $ 4156</p>
  
  <p><br/>Feed me(2 hex digits with the bits prsseeee): 0C
  <br/>Fall Semester
  <br/>12 units
  <br/>Non-Resident
  <br/>No Parking
  <br/>Total Fees = $ 4071</p>
  
  <p>Feed me(2 hex digits with the bits prsseeee): D1
  <br/>Winter Semester
  <br/>1 unit
  <br/>CA Resident
  <br/>Parking
  <br/>Total Fees = $ 139</p>
  
  <p>Feed me(2 hex digits with the bits prsseeee): 91
  <br/>Winter Semester
  <br/>1 unit
  <br/>Non-Resident
  <br/>Parking
  <br/>Total Fees = $ 428</p>
  
  <p><br/>Here is my code: </p>
  
  <pre><code>program SMCFee;
  #include( "stdlib.hhf" );
   static
     total : int32 := 0;
  
     begin SMCFee;
  
     stdout.put("Feed me(2 hex digits with the bits prsseeee):");
     stdin.get(BL);
     mov(total,EAX);
     mov(BL,AL);
     shr(4,AL);
     and( %0000_0011, AL );
     cmp(AL, 00);
     je Fall;
     cmp(AL, 10);
     je Spring;
     jmp Win;
  
     Fall:
     stdout.put("Fall Semester", nl);
         mov(BL,AL);
         shr(7,AL);
         and( %0000_0001, AL );
         cmp(AL,1);
         je SprFallPark;
         add(51, EAX);
         jmp ResCheck;
  
     Spring:
          stdout.put("Spring Semester", nl);
          mov(BL,AL);
          shr(7,AL);
          and( %0000_0001, AL );
          cmp(AL,1);
          je SprFallPark;
          stdout.put("No parking", nl);
          add(51, EAX);
          jmp ResCheck;
  
     SprFallPark:
          stdout.put("Parking", nl);
         add(136, EAX);
         jmp ResCheck;
  
     Win:
          cmp(AL, 11);
          je Summer;
          stdout.put("Winter Semester", nl);
         mov(BL,AL);
         shr(7,AL);
         and( %0000_0001, AL );
         cmp(AL,1);
         je WinSumPark;
         stdout.put("No Parking", nl);
         add(51, EAX);
         jmp ResCheck;
  
         Summer:
         stdout.put("Summer Semester", nl);
         mov(BL,AL);
         shr(7,AL);
         and( %0000_0001, AL );
         cmp(AL,1);
         je WinSumPark;
         stdout.put("No parking");
         add(51, EAX);
         jmp ResCheck;
     WinSumPark:
          stdout.put("Parking", nl);
         add(133, EAX);
         jmp ResCheck;
  
     ResCheck:
         mov(BL,AL);
         shr(6,AL);
         and( %0000_0001, AL );
         cmp(AL,1);
         je Res;
         stdout.put("Non-Resident", nl);
         mov(335,EDX);
         jmp CalcUnits;
     Res:
          stdout.put("CA Resident", nl);
         mov(46,EDX);
         jmp CalcUnits;
  
     CalcUnits:
  
     ForLp:
     mov(BL, AL);
     and(%0000_1111, AL);
     stdout.puti8(AL);
     stdout.put(" units", nl);
     ForLpTerminationTest:
     cmp(AL, 0);
     jle ForLpDone;
     ForLpBody:
     add(EDX, EAX);
     ForLpDecrement:
     dec(AL);
     jmp ForLpTerminationTest;
     ForLpDone:
  
     stdout.put("Total Fees = $");
     stdout.puti32(EAX);
  
     end SMCFee;
  </code></pre>
  
  <p>It must be some logic issues, as let's say I type in cc. It prints out the right strings, but the total amount is wrong. If I type in 4c, I get the right strings, except for parking. It completely skips that, and the total is wrong as well.Thank you for the help. </p>
  
  <p>Edit: Here is a picture of what my results are when I type in CC. As you can see, it correctly types out the categories, but it did not get the same result. My problem is how I have the statement labels, I believe. 
  <a href="https://i.stack.imgur.com/uGjwa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uGjwa.png" alt="Console Window Results"></a></p>