assemblyhexbit-shifthla

College Fee Calculator Assembly(HLA) program


I am writing in assembly, technically HLA(High Level Assembly) and am having trouble with an assignment. Here is the assignment:


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.

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:

Packed Bit Field of Fees Since just 8 bits are being entered, your program should expect to read 2 hexidecimal digits.

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)

Feed me(2 hex digits with the bits prsseeee): CC
Fall Semester
12 units
CA Resident
Parking
Total Fees = $ 688

Feed me(2 hex digits with the bits prsseeee): 4C
Fall Semester
12 units
CA Resident
No Parking
Total Fees = $ 603

Feed me(2 hex digits with the bits prsseeee): 8C
Fall Semester
12 units
Non-Resident
Parking
Total Fees = $ 4156


Feed me(2 hex digits with the bits prsseeee): 0C
Fall Semester
12 units
Non-Resident
No Parking
Total Fees = $ 4071

Feed me(2 hex digits with the bits prsseeee): D1
Winter Semester
1 unit
CA Resident
Parking
Total Fees = $ 139

Feed me(2 hex digits with the bits prsseeee): 91
Winter Semester
1 unit
Non-Resident
Parking
Total Fees = $ 428


Here is my 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;

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.

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. Console Window Results


Solution

  • So the issue was addressed by Michael Petch's comment. The problem was I was writing into AL and AH which was destroying data into EAX. I changed the "total" register to ECX. Once I did that it was just some minor bugs with how I was adding the fees and then it worked correctly.