This is Vic.  Jack of all trades
gamer | doofus | engineer | weirdo | lover | fighter | writer | coder | wit | twit | nerd | canadian
Some miscellaneous ECE341F information that you might find handy. This was required for Lab M1 by the TA (remember how he told you to convert a 12-bit number into hex or do a two's complement in five seconds?).

Mnemonics to remember Two's Complement.
Convert HEX to DEC/BIN and back
Running the 68k Simulator on ugsparc




Mnemonics to remember Two's Complement.
Recall that a two's complement integer has the MSB (Most Significant Bit) as its sign bit. If set to one, you are dealing with a negative integer. To negate it (and figure out its magnitude), memorize this:

FLIP+1 : Essentially, you want to bit-flip (bitwise NOT) the value, and add one to whatever you get. This works BOTH going from positive to negative and vice-versa.

Example: Going from positive to negative values
0001 1010 = 26
----- FLIP! -----
1110 0101
----- +1! -----
1110 0110 = -26 (2's Complement)


Example: Going from negative to positive values
1000 0111 = -121
----- FLIP! -----
0111 1000
----- +1! -----
0111 1001 = 121 (2's Complement)


So remember, it's FLIP+1. Simple. works. :D



Convert HEX to DEC/BIN and back
These are some mental methods to do base conversions. They may or may not work for you. It's the way I do things presently.

Single-digit HEX to DEC:
0 - 9: As-is. If you have trouble doing this, you have issues.
A - F: 10 - 15. Okay, so what's C? If you don't want to memorize, just do it the "easy" way. You know your alphabet, right? C should be the third letter. Subtract one, and pair it with a 1. The answer is 12.

Multiple-digit HEX to DEC:
Similiar approach as above, except for each digit you multiply the value by 16^n (the ^ is exponent), where n is your digit position (starting with n = 0 as the LSB, or Least Significant Bit).

DEC to HEX:
I don't have a really easy way to do this; I memorized powers of 2 up to 2^20 a while ago and it pays off with this. Generally, all I do is take the largest multiple of 16 and mentally "divide and modulus" the DEC value until I am left with something less than 16 DEC. Brute force.

HEX to BIN:
Pretty easy: just split each digit into a group of four bits and do a single-digit HEX to BIN. Often, you may want to use DEC as an intermediate base. For example, converting E in HEX to BIN would usually go E = 14 DEC, which is 1110 BIN (8 + 4 + 2).

BIN to HEX:
Should be just as easy. Take the binary digits as groups of four and convert to a single HEX digit. If there are insufficient bits for a multiple of 4, you can pad them with zeros on the MSB side until you have a group of 4-bits (nibble).

DEC to BIN:
Like the DEC to HEX, I do a brute force "divide and modulus" with the largest power of 2. Once I get the values, I slot them into the appropriate bits.



Running the 68k Simulator on ugsparc
Can't stand going to the Design Centre to do your Lab Prep? Hate it when you run out of time once you get there? Well, BSVC (the 68k simulator available) is not a full-proof solution, but it can help you with code that only requires strict assembler and maybe the serial port. Here's how to get it working.

General Requirements
- access to a ugsparc machine
- X server to run BSVC
- general unix knowledge (minor setup required)


Read the Simulator PDF
It tells you a lot, but not all of it. It's available in the Course Handouts section of the ECE341F course website. Make sure you give it a pass or two and digest it.

Log into an ugsparc machine locally or remotely
Just get into one. If you're not sure how, try a shot at my ECE334 HSPICE document I setup. It's similar.

Add the bsvc directory to your path
You can do it manually each time or add it to the end of your .cshrc file (or wherever you think is best if you know your way around it) in your home directory. The latter is preferable since it's a long path. Make sure it's on a single line.

set path=($path /nfs/ugsparcs/m-r/
    m-r/moshovos/bsvc-2.1/bin)

If you added the path to your .cshrc file, you are supposed to run "source ~/.cshrc" to re-execute the file.

Make the bsvc setup file
Here's a tricky part. The PDF file doesn't fully specify how to get the simulator working for ECE341F. Hence, we have to be creative. If you follow the PDF instructions, you'll have to type a long-ass command to get it running. Even then, you won't have the proper setup for the UltraGizmo's implementation. Without going into details, here's a more suitable setup file I made - it's essentially a modded version of the "original" one.

Slightly better bsvc setup file: ece341f.setup

Save it to your home directory or somewhere easily accessible.

Run bsvc!
Assuming you've setup your paths correctly and you've put the setup file in your home directory, just type "bsvc ~/ece341f.setup &" and it should launch.

68kasm: Compiling code for bsvc
You do not use a68 to compile code for bsvc. Instead, you use the program 68kasm in this form: 68kasm -l <filename>, where <filename> is your assembler .s file. The resulting outputs will be a .h68 file and a .lis file with the name of your source file. If you don't have a .lis, it's because you forgot the "-l" (that's "L" as in 'LOSER' :D ) parameter.

Loading and running the program
Load a program via the file menu (or ctrl-L). You want to load the .h68 file. If you want to trace your program, there is a "program listing" menu item somewhere (it's not hard to find). The buttons at the bottom allow you to run the program or step through it one-by-one. The register display is essentially a constant view of the "rd" command on the UltraGizmo boards.

Notes when writing programs for the simulator
  • Remember to set the PC register to your program's starting address each time you run/trace through it.
  • DO NOT assume that a program running on the simulator will also run perfectly on the UltraGizmo board. There are always minor quirks with simulators.
  • In your program, make sure you setup the system stack BEFORE doing anything else. The UltraGizmo does this automatically for you, but the simulator is generic and hence... dumb. Fortunately, you can do this in one assembler line: movea.l #$8000,a7. Just remember to remove it when you are testing on a real UltraGizmo board. (Note: there is a better way to do this -- see the simulator PDF).
  • If you intend to "run" the program instead of tracing through it, make sure you set a breakpoint at your "trap #15" instruction. This will stop the simulator from running off the end of your code and going nuts. To add a breakpoint, open the Program Listing and click on a line of code. Click again to remove the breakpoint.
  • Make use of the memory viewer (it's in the menus). It's equivalent to the "md" command on the UltraGizmo boards except you can watch it as you step through more easily than on the UltraGizmos.

That's basically it (phew!)
That's all I can think of for now. bsvc won't be useful for all the labs but it should help you with the core instructions that don't require additional hardware (aside from the serial port or a timer). Good luck!

2002.10.06 Note: The serial port configuration does not match that of the UltraGizmo boards. I'm trying to figure it out. More on this later.



Valid XHTML 1.0! Valid CSS 2.0!
© Copyright 2002-2005 Victor Chow.