CS 4380 Devices (3 weeks)
Any education can be preceded by a harangue.
Random harvest of galaxy principle educations:
COUNT .INT 1
INDEX .INT 0
NEXT .INT 5
R .BYT ‘R’
A .BYT ‘A’
Y .BYT ‘Y’
START LDR R0, COUNT
LDR R1, INDEX
ADD R1, R0
STR R1, INDEX
TRP 1
BEGIN MOV R3, R0
CMP R3, R5
BNZ R3, BADX
TRP 3
TRP 0
Jump Educations
Op Principle Description Operands Rate
JMP Branch to Harangue Harangue 1
JMR Branch to harangue in camanifestation record RS 2
BNZ Branch to Harangue if camanifestation record is referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable cipher RS, Harangue 3
BGT Branch to Harangue if camanifestation record is important than cipher RS, Harangue 4
BLT Branch to Harangue if camanifestation record is near than cipher RS, Harangue 5
BRZ Branch to Harangue if camanifestation record is cipher RS, Harangue 6
Agitate Educations
Op Principle Description Operands Rate
MOV Agitate grounds from camanifestation record to contrivance record RD, RS 7
LDA Load the Harangue of the harangue into the RD record. This
education should ONLY purposeeavor if the harangue is associated
with a DIRECTIVE. THIS instruct must NOT be manifestationd to
gain the harangue of an education.
RD, Harangue 8
STR Store grounds into Mem from camanifestation record RS, Harangue 9
LDR Load contrivance record with grounds from Mem RD, Harangue 10
STB Store byte into Mem from camanifestation record RS, Harangue 11
LDB Load contrivance record with byte from Mem RD, Harangue 12
Arithmetic Educations
Op Principle Description Operands Rate
ADD Supplement camanifestation record to contrivance record, consequence in
contrivance record
RD, RS 13
ADI Supplement present grounds to contrivance record. RD, IMM 14
SUB Subtract camanifestation record from contrivance record, consequence in
contrivance record
RD, RS 15
MUL Multiply camanifestation record by contrivance record, consequence in
contrivance record
RD, RS 16
DIV Divide contrivance record by camanifestation record, consequence in
contrivance record
RD, RS 17
Close Educations
Op Principle Description Operands Rate
AND Perform a boolean AND agency, consequence in contrivance
register. This is a close AND referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable a bitwise AND.
RD, RS 18
OR Perform a boolean OR agency, consequence in contrivance
register. This is a close OR referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable a bitwise OR.
RD, RS 19
Compare Educations
Op Principle Description Operands Rate
CMP Set contrivance record to cipher if contrivance is resembling to
source;
Set contrivance record to important than cipher if contrivance is
important than cause;
Set contrivance record to near than cipher if contrivance is near
than cause.
RD, RS 20
Traps
Op Principle Description Operands Rate
TRP Thorough an I/O stratagem sequence (a fashion of frank plan or
library sequence) using record R3.
IMM Rates
1, transcribe integer to exemplar quenched
2, recognize an integer from exemplar in
3, transcribe uncombined tindividual to exemplar quenched
4, recognize a uncombined tindividual from exemplar in
Recognize or transcribe a rate from record R3.
IMM 21
TRP Thorough STOP stratagem sequence.
0, plug program
IMM 21
TRP DEBUG (OPTIONAL)
IMM Rate 99
If you manifestation the TRP its quenchedprostrate must be checked in the
statement of principle you contribute to me!
IMM 21
Directives
Instructive Description
.INT rate Entireocate quantity coercion an integer.
Example:
MONTH .INT 12
DAY .INT 9
YEAR .INT 2005
STUFF .INT 9
.INT 17
.INT 42
.INT 53
.ALN Align the direct byte on a expression expression. (NOT USED)
.BYT rate Entireocate quantity coercion individual byte.
Example:
N .BYT 78 # Manifestation the ascii principle
A .BYT 65
M .BYT 77
E .BYT 69
LETTER_A .BYT ‘A’ # Or manifestation the tone
SCHOOL .BYT ‘U’
.BYT ‘V’
.BYT ‘U’
Registers
Record Description Rate
R[0…7] General contravene integer records contrivanceated R0 through R7 0, 1, 2, 3, 4, 5, 6, 7
PC Program Estimateer, can’t agitate a rate into this record from
a MOV education beside you can vision its rate to another
register.
8
CS 4380 Device 1
Appliance a Virtual Muniment, which can thorough the Trial Program pland adown.
Manifestation the succeedingcited plan coercion complyting entire devices.
Comply your device via canvas.
Your device MUST be packaged in a zip perfect the evidence of this .zip is:
YourName_p1.zip
Where YourEvidence is your evidence
p1 is the evidence of the device
Note: Canvas perfect entireow you to recomply your device as manifold opportunitys as you lack. Simply the most
vulgar statement perfect be kept my Canvas and triced by me. I extremely suffer you to comply future
and frequently. If you hold to the conclusive instant and Canvas, the internet or your computer doesn’t purposeeavor
then THIS IS A MISTAKE on your segregate.
Your device must include:
1. Camanifestation Principle coercion your device.
2. Referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributablees prostrate immediately in Canvas that recounts me how to thorough your program and other facts you
lack me to understand. Simply wanted if your device doesn’t purposeeavor as I would contemplate-control ( vm,exe proj1.asm ). If
you understand you bear a bug reestimate me. I ponder it is ameliorate to understand you bear a bug than it is to contempdeceased relish I
found a bug you bear no understandledge of.
3. proj1.asm this is your galaxy perfect. This is what I trice. This perfect must be certain as a instruct
outcord discussion. I may reevidence the perfect regular to bridle that your principle veritably purposeeavors. Don’t misevidence your
project
4. vm.exe this is your calmd executable. You must despatch an executable if your tongue doesn’t
maintenance this then YOU Must construct me a script to thorough your program (vm.bat). Recognize if you don’t
understand what this instrument.
o Your executable must sanction a instruct-outcord discussion of the galaxy perfect that it manifestations.
 vm.exe proj1.asm Don’t misevidence your device
 vm.bat proj1.asm Don’t misevidence your device
 As hanker as you concession me manifest education on how to hurry your scripting
tongue in Canvas I perfect sanction it beside you veritably should collect to manifestation the
vm.bat perfect
o Be very cautious using Visual Studio to mould your program liberal year students despatch me
executes that perfect referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable thorough on Windows becamanifestation they are calmd erroneously. Always
thorough your program quenchedside of the harvest environment precedently despatching it to me (or
anyindividual else).
o Your program must referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable lean succeeding hurryning. I perfect thorough it at instruct-outcord and perfect contemplate-for
it to perfect when the program is produced.
Important Referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributablees:
 Be secure to check entire debug quenchedprostrate in the developed asm/vm statement you
submit.
 Mould secure you produce me an executable that hurrys on Windows. You can
bear an executable to my appointment to hurry.
o THIS DOESN’T NEED TO BE YOUR PROJECT
o NO, I WILL PRE-GRADE IT THEN LET YOU FIX IT
 Recognize the galaxy perfect evidence from the instruct-outcord don’t unfeeling principle
it.
 Your vm must NOT lean at the instruct-outcord holding coercion inprostrate succeeding
the program has thoroughd!
 You are making an appalling selfreliance if you ponder you can gain a
perishing trice on a device quenchedside completing liberal component of the
project.
o I don’t trice camanifestation principle that doesn’t calm and thorough
o I don’t produce you confidence coercion programs that jar when hurry
o This regularityatize is NOT relish peewee soccer you perfect referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable be producen
confidence coercion your purposeeavor simply your achievements.
 Don’t wanton this device can be thoroughd by smooth an average
CS student as hanker as you begin today!
o When Canvas closes it perfect referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable be reopened.
o Don’t despatch deceased devices to me via email. Thorough them on
time.
o Comply Future… Comply Frequently…
 If you bear questions encircling if the tongue you are using perfect thorough
on my muniment conclude by my appointment and aim it quenched.
o NO I won’t pre-trice your device
o Remember you simply want an harvest program referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable a thoroughd
project.
You may referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable transmute the syntax of the educations! I perfect referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable trice it
You may referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable transmute the semantics of the educations! I perfect referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable trice it
You may referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable supplement educations. I perfect referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable trice it
When in vacillate ASK!
Trial Program
Transcribe the succeedingcited galaxy program using your galaxy tongue.
Place the succeedingcited catalogue of integers in recollection
A = (1, 2, 3, 4, 5, 6)
B = (300, 150, 50, 20, 10, 5)
C = (500, 2, 5, 10)
Place your liberal evidence “Conclusive Evidence, Principal Evidence” in commensurate recollection.
Program Quenchedprostrate (supervene the quenchedprostrate coercionmatting accurately. I’m very picky
on this assignment referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable so abundantly on the others.)
1) Imprint your evidence “Conclusive Evidence, Principal Evidence” on the cloak. You don’t want the quotes beside you do want
the comma.
2) Imprint a bleak sketch.
3) Supplement entire the components of catalogue B concomitantly; imimprint each consequence (interposed and developed) on cloak. Prostrate 2
spaces betwixt each consequence.  dissipated ponderation to this (e.g., 450)  dissipated ponderation to this
4) Imprint a bleak sketch.  dissipated ponderation to this
5) Multiply entire the components of catalogue A concomitantly; imimprint each consequence (interposed and developed) on cloak. Prostrate
2 quantitys betwixt each consequence. (e.g., 2)  dissipated ponderation to this
6) Imprint a bleak sketch.
7) Divide the developed consequence from segregate 3, by each component in catalogue B (the consequences are referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable cumulative). Prostrate
2 quantitys betwixt each consequence. (e.g., 1)
8) Imprint a bleak sketch.
9) Subtract from the developed consequence of segregate 5 each component of catalogue C (the consequences are referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable cumulative). Prostrate
2 quantitys betwixt each consequence. (e.g., 220)
Engender a instructive coercion each component of the catalogue and missive of your evidence.
Example.
A1 .INT 1
A2 .INT 2
A3 .INT 3
C .BYT ‘C’
u .BYT ‘u’
r .BYT ‘r’
Grading
The device is merit 100 points Planatic Deductions are fascinated extempore the apex precedently
individual Device Deductions are made. Planatic Deductions are relish penalties coercion
doing star a greater shouldn’t do becamanifestation they are regular as-courteous essential and unblended.
A basic plan of the grading regularity beside this doesn’t necessarily oversprecognize liberal case:
Entire Device trices in CS 4380 are Performance-based (Mastery Trices) purport you perfect
simply entertain confidence coercion components you thorough appropriately referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable things you violate. You
should never contemplate-control to entertain confidence coercion components you purposeeavor on beside do referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributablehing.
Systematic Deductions
Deceased (no excuses; comply future; comply frequently) -100
Naming executable or asm perfect erroneously -10
vm.exe/vm.bat, proj1.asm
Sending an un-executable device -20
Doubles with each extemporeense (most frequently a VisualStudio progeny)
VM leans when perfected -10
VM jares during deed -50 or important
Debug Quenchedprostrate -10
Failure to despatch entire the components in your zip -10
Referable attributable attributable attributable attributable attributable attributable succeedingcited educations which coercionces me
to retrice your device (e.g., altering educations) -20
Device Deductions
Each Superior component -20 max
 Your Evidence, Supplement, Multiply, Divide, Subtract, Plug, Modify and Re-run
Projects with a trice of 60 or inferior are high beside evidence momentous progenys in your
harvest skills or opportunity oration. While it’s quiescent likely to ignoring the regularityatize with
such a trice on a uncombined device; such a trice generally evidences quenchedside a weighty purposeeavor
on your segregate, you’ll purpose up referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable ignoringing this regularityatize as you’ll remain to bear totals on
future devices as courteous.
The progeny isn’t making individual out-of-sorts reach and then having to oversprecognize coercion it the intermission of
the regularityatize by making amiable trices to ignoring. If you perfect beset down with Excel or a
calculator you can abundantly discern what I average. The progeny is most students who gain a impecunious
device trice perfect bear impecunious trices on succeeding devices and ultimate trial
grades.
Deceased devices perfect referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable be triced. Don’t pray. However, if you interest the opportunity to bear it to
my appointment and beset down with me, I perfect dialogue to you encircling it. Smooth a 0 on a uncombined device
doesn’t average you perfect miscarry the regularityatize if your trial, homeendeavor and other device scores are
high.

Hints:
Transcribe the unblendedst Galaxy program you want to thorough the trial program. You don’t want LOOPS
or REGISTER INDIRECT ADDRESSING to thorough the device. Then transcribe an assembler and a
Virtual Muniment to thorough your program.
Do this as an incremental Harvest Device referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable individual large total.
Assembly
Source
Code
.asm
2 Ignoring
Assembler
Virtual
machine
VM Device is span programs in individual.
 Appliance a Span-Ignoring Assembler. The educations you appliance are to be fascinated from the agitate
instructions, arithmetic educations, stratagem educations. Referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable entire educations are wanted coercion this device, beside
you perfect want to appliance entire these education (plus a rare over) by the opportunity you reverse in the conclusive device.
In the principal ignoring engender a Symbol Table (Associative Map)
The clew of the Symbol Table is a Harangue (Code, Grounds) from an galaxy program. The rate associated with
the clew is the subsidence of the Harangue (Harangue  Harangue). Compute the harangue of the Harangue during the principal
pass.
Instructions estimate coercion N bytes of quantity
.BYT Variables estimate coercion 1 bytes of quantity
.INT Variables estimate coercion K (a min of 4) bytes of quantity
Ignoring #1
Recognize a outoutcord of citation
Break citation on quantitys
Discover optional harangue
Discover Operator—Discover Operands—Increment estimateer by education
OR
Discover Instructive—Discover Grounds—increment estimateer by grounds size
Generate Error Message
Load harangue to Symbol Table
 In the succor ignoring engender byte principle coercion your program. Using the Symbol Table appropriate Harangues to
addresses. Your byte principle must be entire numeric grounds: (e.g., ADD is 13, R7 is 7, Harangue A is 1024, restrainteseeing.)
Ignoring #2
Recognize a outoutcord of citation
Break citation on quantitys
Discover optional harangue
Discover Operator—Discover Operands—Lookup harangue coercion harangues—Appropriate education to bytecode—
Load byteprinciple to recollection—Increment estimateer by education
OR
Discover Instructive—Discover Grounds—Appropriate grounds to binary—Load binary grounds to recollection—increment
against by grounds size
Generate Error Message
To contravene education in the principal and succor ignoring recognize individual (1) outoutcord of grounds at a opportunity from your
galaxy perfect.
 Transcribe a Virtual Muniment (VM) that can thorough your byte principle. To mould things unblendedr embed your
assembler in your VM. Thus your program perfect purposeeavor as:
 Assembler Ignoring 1 – Contravene education & Load Symbol Table
 Assembler Ignoring 2 – Contravene education, Engender Byte & Load Byte Principle to Recollection
 Thorough Byte principle Program
Don’t aim to jump these steps. It perfect referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable purposeeavor and it’s referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable easier!
Separating your Assembler and VM perfect mould completing CS4380 over difficult!! Don’t do it!
 You perfect want the succeedingcited harangue modes coercion this device
 Direct EA = Harangue
 Record EA = Record
 Present – may besides be very manifestationful
Recollection layquenched is individual of your largegest progenys. There are a rare superior options to ponder.
IF you bear dindividual Device 0 you are perfected with this segregate of the device!
 Stratagems 1 and 3 are manifestationd coercion quenchedprostrate to the cloak. Referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributablee there is NO TRAP THAT CAN WRITE OR
READ A STRING! Don’t engender individual!
 Strongly ponder sustaining comments. Regular bear your assembler misconsider the comments when
they are encountered. Comments perfect aid me trice your devices, smooth over they perfect aid you transcribe
your devices.
MUL R5, R6 ; Multiply A * B
 Don’t overcontempdeceased TESTING. I’ve already dialogueed encircling using TDD ahanker with incremental contrivance,
implementation and trialing. There are span supplementitional steps you can interest to trialing that perfect ensecure the
quality of your device and the products you built.
1. Don’t appropinquation trialing as a regularity to examine your plan purposeeavors always
appropinquation trialing a regularity to examine your plan doesn’t purposeeavor. Don’t hurry trial
you understand perfect purposeeavor hurrys trials you estimate perfect miscarry!
a. If you estimate the Earth is tame or the Sun circles the Earth or Apple pretended the momanifestation or
Java pretended Garbage Collection you can discover some indisputable to maintenance this. However, it
is unblended to disexamine each of these statements.
2. Discover span other students gate CS4380 and uninterruptedly you bear perfect your devices
compare the quenchedprostrate of your devices. It is virtually imlikely coercion three of you
gain the similar injustice key UNLESS you’re purposeeavoring as-courteous air-tight in
developing your key. CS4380 is NOT A GROUP Device!
a. Don’t distribute principle THIS IS CHEATING.
b. Swapping ideas is OKAY!
How to appropinquation a large device (School or Purposeeavor):
 Never construct star becamanifestation it is propitious or cleaver.
 Simply construct what is wanted to thorough the device.
o If you perfect future you susceptibility bear loose opportunity!
 Focus on what you must perfect referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable what you
lack to do.
 Ponder the ordain in which you must construct things
to mould the best journey.
 Manifestation twain apex-down and bottom-up contrivance &
implementation.
Assembler Ignoring 1
Recognize Galaxy Camanifestation Perfect
Group chars into Tokens (Lexical Analysis)
Regular Expressions
Tokenizer (C strtok)
String Compare
Finite State Muniment
Bridle Syntax of Educations (Syntax Analysis)
Ensecure that entire educations are segregate of the defined Galaxy Tongue.
[ optional ]
Directives:
[Label] .INT Integer
.ALN
[Label] .BYT Integer
Instructions:
[Label] Operator Operand1 [Operand2]
Operand1 is Record, Harangue or Present
Operand2 is Record, Harangue or Present
Load Defined Harangues into a Symbol Table
Labels on Instructives (Recollection entireocation)
Labels on Educations (Branch subsidences)
And contravene there harangue!
Symbol Table
Harangue  Recollection Harangue + other
Bridle that Defined Harangues are unique
Assembler Ignoring 2
Bridle that Referenced Harangues are defined in the Symbol Table
LDR R1, NUTMEG is harangue NUTMEG defined (what is its harangue?)
JMP NEXT is harangue NEXT defined (what is its harangue?)
Generate Principle (Byte Principle)
We bear a very unblended LOADER on this device when you agitated byteprinciple and grounds to recollection you’re
implementing a LOADER.
Enprinciple Galaxy statements to some fashion of bytecode: Mould your educations urban
length
Op Principle Operand 1 Operand 2
I strongly hint you manifestation an integer coercion the Op Principle, Operand 1 and Operand 2 thus your urban size
education perfect be 12 bytes hanker. This is NOT optimal beside you don’t want optimized keys regular a amiable
workable key.
Directives (Labels) are NOT placed immediately into recollection. Simply the grounds is placed into recollection!!!!!!!
Thorough Byte principle Program (Virtual Muniment)
Register-Register
(Load/Store)
memory
Real Recollection Layout
Code
Static Grounds
Heap
Stack
Code
Static Grounds
Heap
Stack
Pick individual key or the other Don’t Mix them concomitantly that is referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable a key.
That is a MESS!
 Begining with Principle principal moulds it self-possessed to particularize your moderate PC
(PC=0).
 Begining with Static Grounds principal discernms to be over recognizeable than the
inverse.
Regular mould a excellent a cleave to it! Don’t waffle that regular wastes opportunity.
Virtual Muniment
NOTE: Fashion Cast as entireowed by C can be very aidful here!!!
MemoryFashion mem[MEM_SIZE];
Static Grounds (Byte or 4 byte Int)
Bytecode
Heap
Stack
BytePrinciple IR;
Object or Structure
 opPrinciple is the education to thorough.
 opd1 is the principal operand of the education.
 opd2 is the succor operand of the education.
PC is an refutation into mem[].
RegisterFashion reg[REG_SIZE];
Integer
R0 is 0 & R1 is 1
Encoding records as an refutation into reg[].
The Large Switch (VM)
PC = Beginning_Address;
Vulgar = True;
# this pseudo principle is referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable planned to thorough
while(Running) {
IR = mem.fetch(PC); # bear the vulgar education from recollection
switch(IR.opCode) {
case ADD:
reg[IR.opd1] = reg[IR.opd1] + reg[IR.opd2];
PC++;
break;

case MOV:
reg[IR.opd1] = reg[IR.opd2];
PC++;
break;

case LDR:
reg[IR.opd1] = mem.getInt(IR.opd2);
PC++;
break;

}
}

~~~For this or similar assignment papers~~~