3

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

This is the assignment

https://i.stack.imgur.com/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;
  • 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. – Ira Baxter Jan 23 '16 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 http://i.imgur.com/0XovkvZ.png instead of the correct response. I went ahead and updated the first post – CodingIsHardForMe Jan 24 '16 at 03:55
  • It may help you to know that "coding is easy", but "understanding what (my) code does is hard", even for grizzled old salts :-} There's no substitute for staring at the code line by line and asking, "what does this really do?". – Ira Baxter Jan 24 '16 at 04:10
  • 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. – Ira Baxter Jan 24 '16 at 04:15
  • Ahh! Okay that helps. So would it be dumb to `mov(BL, AL)` and then `AND` AL? – CodingIsHardForMe Jan 24 '16 at 04:18
  • That might work, if you did the move before you mask BL. In general, might need to get a fresh copy of the input several times; it seems clear that you have to inspect the input several ways. – Ira Baxter Jan 24 '16 at 04:25
  • And when you say "mask BL". What do you mean by masking? Does that mean edit and play around with? – CodingIsHardForMe Jan 24 '16 at 04:26
  • 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). – Ira Baxter Jan 24 '16 at 04:27
  • 1
    Having shown the problematic code, you should probably add as another chunk, the final result to show how you fixed it. Enjoy. – Ira Baxter Jan 24 '16 at 04:53

2 Answers2

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;
Fifoernik
  • 9,779
  • 1
  • 21
  • 27
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.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341