I am writing in assembly, technically HLA(High Level Assembly) and am having tro
ID: 3914616 • Letter: I
Question
I am writing in assembly, technically HLA(High Level Assembly) and am having trouble with an assignment. Here is the assignment:
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 because 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 labels but I'm not sure. Any guidance would be helpful.
Semester Enrolled Units CA Resident? Parking Decal?Explanation / Answer
#include( "stdlib.hhf" ); static totalfee : int32 := 0; begin Fee; stdout.put("Enter number(2 hex digits with the bits prsseeee):"); stdin.get(BL); mov(totalfee,ECX); 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(ECX); end Fee;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.