Look
Before solve the following electronics engineering problem, here have some point you should know
- only have few components could be given. For example, the game only have two type micro-controller MC4000 and MC6000 ,both of them had limit the assembly code size,which the forth only allow 9 rows and 16 characters a column for you to coding assembly language, another only allow 14 rows and column’s size is same as forth.
- only have Simple io and XBUS as micro-controller’s interfaces. MC4000 have p0 and p1 as it’s simple io,MC6000 same. simple io values are continous signal levels from 0 to 100. MC4000 have x0 , x1 as it’s xbus, while MC600 have x0,x1,x2,x3 as it’s xbus. Xbus values are discrete data packets from -999 to 999.
Here have a simple usage of MC4000.
Assembly Language in the game
#move instruction
mov 100 p1 #take 100 to p1 that means port register
#null instruction
nop #no effect
#arithmetic instructions
add 3 #add 3 to acc that means accumulator register
sub 4 #sub 4 by acc
mul 1 #mul 1 by acc
not #if the value in acc is 0,store a value of 100 in acc.
otherwise,store a value of 0 in acc.
#sleep instructions
slp 6 #sleep for 6 time units
slx x0 #sleep until data is available to be read on the x0
#test instructions
teq x0 1 #query whether x0 is equal to 1
if x0 is equal to 1,enable + instruction.
Otherwise,enable - instruction.
tgt p1 p0 #query whether p1 is greater than p0
....
tlt p1 p0 #query whether p1 is less than p0
....
tcp x0,p1 #compare x0 and p1 and comes three results.
if x0 is greater than p1,enabled + instruction.
if x0 is equal to p1,enabled neither + or - instruction.
if x0 is less than p1,enable - instruction,
#decimal bit operation instructions
dgt 2 #store the number in position 3.if the value in acc is 734,
store 7 to acc.
dst 0 9 #store a changed number.if the value in acc is 123,
store 129 to acc.
a infrared alarm
The following picture is the question details.
So, we have this messages:
- current time,maybe a number.
- a start time and a end time,could used as constant.
- a sensor input and a alarm output.
- the alarm should actived in a time period and meanwhile sensor input the number that larger than 19.
\;
\;
\;
\;
Here is the solution below.
slx x0
teq x0 1
+ tgt p0 19
+ mov 100 p1
- mov 0 p1
off:
teq p1 x2
+ jmp on
mov 0 x1
slp 1
jmp off
on:
teq p1 x3
+ jmp off
mov 1 x1
slp 1
jmp on
module in assembly code
label_A:
query whether something happened
if something commit then jump to label_B
otherwise run the following code
...
...
at the end of the module,jump back to label_A with out query