3

I'm currently trying to do my assignment but I'm having some issues.

This is the assignment

https://i.sstatic.net/7KRAL.png enter image description here

As it is right now, When I put 'CC' I only get back

Feed me(2 hex digits with the bits prsseeee):CC
Fall Semester
Total Fees = $ 97

When I should be getting back

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

Here is what I've done so far.

I'm also only allowed to use

** http://homepage.smc.edu/stahl_howard/cs17/FileManager/referenceguides/referenceguideiv.htm

so far

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);

    ror(4, BL);
    and(%0000011, BL);

    cmp(BL, %00);
    je Fall;
    cmp(BL, %01);
    je Winter;
    cmp(BL, %10);
    je Spring;
    cmp(BL, %11);
    je Summer;

    Fall:
        stdout.put("Fall Semester",nl);
        add(50, total);
        ror(1, BL);
        and(%0000001, BL);
        cmp(BL, 0);
        je NoFallResident;
        cmp(BL, 1);
        je FallResident;
            FallResident:

                rol(6, BL);
                and(%00001111, BL);
                mov(BL, AL);
                stdout.put(AL,nl);
                stdout.put("CA Resident");
                FallUnitCheck:
                cmp(AL, 0);
                jle FallParkingCheck;
                add(46, total);
                dec(AL);
                jmp FallUnitCheck;
                    FallParkingCheck:
                        ror(7, BL);
                        and(%0000001, BL);
                        cmp(BL, 0);
                        je NoFallResidentParking;
                        cmp(BL, 1);
                        je FallResidentParking;
                        FallResidentParking:
                            stdout.put("Parking",nl);
                            add(85, total);
                            jmp zend;
                        NoFallResidentParking:
                            jmp zend;
            NoFallResident:
                ror(1, BL);
                and(%0000001, BL);
                cmp(BL, 0);
                je FallNoResidentParking;
                cmp(BL, 1);
                je NoFallNoResidentParking;
                    FallNoResidentParking:
                    NoFallNoResidentParking:


    Winter:
        add(47, total);
        jmp zend;


    Spring:
        add(47, total);
        jmp zend;


    Summer:
        add(50, total);
        jmp zend;

    zend:
        stdout.put("Total Fees = $ ",total);
end SMCFee;
9
  • 1
    Just looking at your code, "jmp zend" (an unconditional jmp) appears to make the code following the jmp entirely useless since that code can't be executed. If you expect that code to be executed, either you haven't stared at your code long enough or you don't understand what the jmp does. If you have that dead code with the intent that it stays dead, people would say your program is not well written. Hope this gives a clue; good responses from you may get you further advice. Commented Jan 23, 2016 at 14:43
  • Oh god, I'm retarded. I guess I just missed where I wrote jmp zend but now when I put CC, I get i.imgur.com/0XovkvZ.png instead of the correct response. I went ahead and updated the first post Commented Jan 24, 2016 at 3:55
  • 1
    A hint: when you AND to BL, you wipe out all bits in BL except for the enabled ("1") mask bits. If you don't understand this, go read about AND, REALLY CAREFULLY. If you do ... then your program gets into the Fall code having figured out it is fall, but now BL has nothing in but the bits for the semester. You need to pick up a fresh copy of the input, and inspect that. Commented Jan 24, 2016 at 4:15
  • 2
    The term "mask" refers to a binary bit pattern like those you are using (think of a paint mask that controls the spray pattern to just the places you want). The term "to mask" means to use an AND instruction to extract the bits you want. After masking, you can play around with the masked bits to hearts content, as long as you remember the other bits are "gone" (zeroed). Commented Jan 24, 2016 at 4:27
  • 1
    Having shown the problematic code, you should probably add as another chunk, the final result to show how you fixed it. Enjoy. Commented Jan 24, 2016 at 4:53

2 Answers 2

2

I think you had a few errors:

  • Wrong radix prefix [noted by @Fifoernik]
  • Misplaced JMP instructions
  • A misunderstanding of how AND is being used for "masking"
  • Loss of the input data after masking.

Learning to handle binary values is initially un-intuitive.

These are pretty typical errors of green assembly language programmers. Getting past them to a running program really helps build confidence. Do a lot more of this, you'll be pretty good at it.

Learn to mentally simulate your code. This pays off like gold.

Sign up to request clarification or add additional context in comments.

Comments

2
cmp(BL, 00);
je Fall;
cmp(BL, 01);
je Winter;
cmp(BL, 10);
je Spring;
cmp(BL, 11);
je Summer;

You are forgetting the binary prefix %. The first 2 compares don't need it but the last 2 wrongly compare with ten (10) and eleven (11)!

cmp(BL, %00);
je Fall;
cmp(BL, %01);
je Winter;
cmp(BL, %10);
je Spring;
cmp(BL, %11);
je Summer;

1 Comment

Good catch, although the code still isn't working =/ I've updated the first post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.