Question: 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
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 Summer 2018, the enrollment fee is $46/unit for residents and $370/unit for all others. The student services fee is $48 for Winter or Summer and $51 for Fall or Spring. The purchase 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: 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 = $ 4576 Feed me(2 hex digits with the bits prsseeee): 0C Fall Semester 12 units Non-Resident No Parking Total Fees = $ 4491
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 = $ 463
Here is my code:
program SMCFee;
#include( "stdlib.hhf" );
static
iTotal: int32 := 0;
I: int8 := 0;
begin SMCFee;
stdout.put( "Feed me(2 hex digits with the bits prsseeee):" ); //Get info from user
stdin.get( BL ); //Store in the BL reg
mov( iTotal, EBX ); //Move the var iTotal to the EBX reg
mov( BL, AL ); //Move the contents of the BL reg to the AL reg
shr( 4, AL ); //Shift right 4 the contents of AL reg
and( %0000_0011, AL ); //Using AND to force the lower bits of AL to 0 and isolate bits 0 and 1
cmp( AL, %0000_0000 ); //Compare AL to 0
je Fall; //If equal jump to Fall
cmp( AL, %0000_0010 ); //Compare AL to 10
je Spring; //If equal jump to Spring
cmp( AL, %0000_0001 ); //Compare AL to 1
je Winter; //If equal jump to Winter
cmp( AL, %0000_0011 ); //Compare AL to 11
je Summer; //If equal jump to Summer
Fall:
stdout.put( "Fall Semester", nl );
//Determine # of credits
mov( BL, AL ); //Move original contents of BL to AL thereby overwriting AL
and( %0000_1111, AL ); //Using AND to force the lower bits of AL to 0 and isolate bits 0 through 3
mov( AL, CH ); //Move AL (credits) to CH
stdout.puti8( CH ); //Print to number of units in decimal format
stdout.put( " units", nl);
//Determine CA Residency Status
mov( BL, AL ); //Move original contents of BL to AL thereby overwriting AL
shr( 6, AL ); //Shift right 6 the contents of AL reg
and( %0000_0001, AL ); //Using AND to force the lower bits of AL to 0 and isolate bit 0
cmp( AL, 1 ); //Compare AL to 1
je CARes; //If equal jump to CA Res
jne NonRes; //If not equal jump to Non Res
Spring:
stdout.put( "Spring Semester", nl );
//Determine # of credits
mov( BL, AL ); //Move original contents of BL to AL thereby overwriting AL
and( %0000_1111, AL ); //Using AND to force the lower bits of AL to 0 and isolate bits 0 through 3
mov( AL, CH ); //Move AL (credits) to CH
stdout.puti8( CH ); //Print to number of units in decimal format
stdout.put( " units", nl);
//Determine CA Residency Status
mov( BL, AL ); //Move original contents of BL to AL thereby overwriting AL
shr( 6, AL ); //Shift right 6 the contents of AL reg
and( %0000_0001, AL ); //Using AND to force the lower bits of AL to 0 and isolate bit 0
cmp( AL, 1 ); //Compare AL to 1
je CARes; //If equal jump to CA Res
jne NonRes; //If not equal jump to Non Res
Winter:
stdout.put( "Winter Semester", nl );
//Determine # of credits
mov( BL, AL ); //Move original contents of BL to AL thereby overwriting AL
and( %0000_1111, AL ); //Using AND to force the lower bits of AL to 0 and isolate bits 0 through 3
mov( AL, CH ); //Move AL (credits) to CH
stdout.puti8( CH ); //Print to number of units in decimal format
stdout.put( " units", nl);
//Determine CA Residency Status
mov( BL, AL ); //Move original contents of BL to AL thereby overwriting AL
shr( 6, AL ); //Shift right 6 the contents of AL reg
and( %0000_0001, AL ); //Using AND to force the lower bits of AL to 0 and isolate bit 0
cmp( AL, 1 ); //Compare AL to 1
je CARes; //If equal jump to CA Res
jne NonRes; //If not equal jump to Non Res
Summer:
stdout.put( "Summer Semester", nl );
//Determine # of credits
mov( BL, AL ); //Move original contents of BL to AL thereby overwriting AL
and( %0000_1111, AL ); //Using AND to force the lower bits of AL to 0 and isolate bits 0 through 3
mov( AL, CH ); //Move AL (credits) to CH
stdout.puti8( CH ); //Print to number of units in decimal format
stdout.put( " units", nl);
//Determine CA Residency Status
mov( BL, AL ); //Move original contents of BL to AL thereby overwriting AL
shr( 6, AL ); //Shift right 6 the contents of AL reg
and( %0000_0001, AL ); //Using AND to force the lower bits of AL to 0 and isolate bit 0
cmp( AL, 1 ); //Compare AL to 1
je CARes; //If equal jump to CA Res
jne NonRes; //If not equal jump to Non Res
CARes:
stdout.put( "CA Resident", nl );
jmp CAResFees; //Jump to CA Res Fees
NonRes:
stdout.put( "Non-Resident", nl );
jmp NonResFees; //Jump to Non Res Fees
CAResFees:
mov( 46, ECX ); //Move $46 to ECX reg
add( ECX, EBX ); //Add $46 to total (EBX)
CAForLp: //Begin For Loop
InitializeCAForLp: //I = 0
mov( 0, I );
CAForLpTerminationTest: //Is I >= number of units (CH)? Then terminate
cmp( I, CH );
jnl CAForLpDone;
CAForLpBody:
add( ECX, EBX ); //Add $46 to total (EBX)
CAForLpIncrement:
inc( I );
jmp CAForLpTerminationTest;
CAForLpDone:
jmp Parking; //Jump to Parking
NonResFees:
mov( 370, ECX ); //Move $370 to ECX reg
add( ECX, EBX ); //Add $370 to total (EBX)
ForLp: //Begin For Loop
InitializeForLp: //I = 0
mov( 0, I );
ForLpTerminationTest: //Is I >= number of units (CH)? Then terminate
cmp( I, CH );
jnl ForLpDone;
ForLpBody:
add( ECX, EBX ); //Add $370 to total (EBX)
ForLpIncrement:
inc( I );
jmp ForLpTerminationTest;
ForLpDone:
jmp Parking; //Jump to Parking
Parking:
mov( BL, AL ); //Move the contents of the BL reg to the AL reg
shr( 4, AL ); //Shift right 4 the contents of AL reg
and( %0000_0011, AL ); //Using AND to force the lower bits of AL to 0 and isolate bits 0 and 1
cmp( AL, 0 ); //Compare AL to 0
je FallSpringParking; //If equal jump to Fall Spring Parking
cmp( AL, 10 ); //Compare AL to 10
je FallSpringParking; //If equal jump to Fall Spring Parking
cmp( AL, 1 ); //Compare AL to 1
je WinterSummerParking; //If equal jump to Winter SummerParking
cmp( AL, 11 ); //Compare AL to 11
je WinterSummerParking; //If equal jump to Winter Summer Parking
FallSpringParking:
mov( BL, AL ); //Move original contents of BL to AL thereby overwriting AL
shr( 7, AL ); //Shift right 7 the contents of AL reg
and( %0000_0001, AL ); //Using AND to force the lower bits of AL to 0 and isolate bit 0
cmp( AL, 1 ); //Compare AL to 1
je FSYesParking; //If equal jump to YesParking
jne FSNoParking; //If not equal jump to NoParking
WinterSummerParking:
mov( BL, AL ); //Move original contents of BL to AL thereby overwriting AL
shr( 7, AL ); //Shift right 7 the contents of AL reg
and( %0000_0001, AL ); //Using AND to force the lower bits of AL to 0 and isolate bit 0
cmp( AL, 1 ); //Compare AL to 1
je WSYesParking; //If equal jump to YesParking
jne WSNoParking; //If not equal jump to NoParking
FSYesParking:
stdout.put( "Parking", nl );
mov( 85, EDX ); //Move $85 to EDX
jmp TotalFees; //Jump to Total fees
FSNoParking:
stdout.put( "No Parking", nl );
mov( 0, EDX ); //Move $0 to EDX
jmp TotalFees; //Jump to Total fees
WSYesParking:
stdout.put( "Parking", nl );
mov( 45, EDX ); //Move $45 to EDX
jmp TotalFees; //Jump to Total fees
WSNoParking:
stdout.put( "No Parking", nl );
mov( 45, EDX ); //Move $45 to EDX
jmp TotalFees; //Jump to Total fees
StudentServices:
mov( BL, AL ); //Move the contents of the BL reg to the AL reg
shr( 4, AL ); //Shift right 4 the contents of AL reg
and( %0000_0011, AL ); //Using AND to force the lower bits of AL to 0 and isolate bits 0 and 1
cmp( AL, 0 ); //Compare AL to 0
je FallSpringSS; //If equal jump to Fall Spring Student Services
cmp( AL, 10 ); //Compare AL to 10
je FallSpringSS; //If equal jump to Fall Spring Student Services
cmp( AL, 1 ); //Compare AL to 1
je WinterSummerSS; //If equal jump to Winter Summer Student Services
cmp( AL, 11 ); //Compare AL to 11
je WinterSummerSS; //If equal jump to Winter Summer Student Services
FallSpringSS:
add ( 51, EBX ); //Add $51 to total (EBX)
jmp TotalFees; //Jump to Total Fees
WinterSummerSS:
add ( 48, EBX ); //Add $48 to total (EBX)
jmp TotalFees; //Jump to Total Fees
TotalFees:
stdout.put( "Total Fees = ");
stdout.puti32( EBX );
end SMCFee;
I must be having some logic issues becuase my code compiles but regardless of the hex number entered I get the same result Fall Semester, 0 units, Non-Resident, Parking, and $740 in fees. I'm guessing the problem is with my lables but I'm not sure. Any guidence would be helpful.
Semester Enrolled Units CA Resident? Parking DecalStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
