(i) (ii) (iii)
1000 0110 1000 0111 1000 1111
+0000 0101 +1111 1110 +1000 0000
--------- --------- ---------
[B2.] Assembly Language Programming and the Assembly Process
L0: LODD a0
SUBD a1
JPOS L2
JZER L2
L1: LOCO 1
STOD a2
JUMP L3
L2: LOCO 0
STOD a2
L3: ...
a0, a1, ..., a10 will be at addresses 500Hex, 501Hex,
...50AHex.
[B3.] Input-Output, and Subprogam Handling
Mac-1a uses memory-mapped input-output, wherby some memory cells are mapped to input-output ports; for simplicity we assume that there are only two ports, one connected to a standard-input device, another connected to a standard-output device.Input: data port is mapped to 4092/FFCHex (lower-order byte = data byte); status port is mapped to 4093/FFDHex, when the sign bit (most significant bit) is set, this denotes data available.
Output: data port is mapped to 4094/FFEHex (lower-order byte); status 4095/FFFHex; sign bit set denotes ready ...
Briefly, explain the principle used in both read and write operations.
call and retn; you should mention
the roles of the stack and stack pointer; illustrate your answer with
appropriate examples / diagrams. In your answer please mention the major
reasons why call and retn cannot be replaced by
simple jump instructions.
int max(int x, int y)
{
if (x > y) return x;
else return y;
}
and the call: c = max(a, b);
Pay particular attention to: (i) in the calling program, how to pass the
two arguments via the stack, and how to call the subprogram; (ii) in
subprogram max itself, how to access the two parameters
x, y. Hint: lodl, and subl - for the
comparison.
Appendix 1.1, Mac-1a Instruction Set - limited version of Mac-1, with machine code
------------------------------------------------------------------- Binary Mnemonic Name Action(s) ------ -------- ---- --------- -------------------------------------------------------------------- 0000XXXXXXXXXXXX lodd Load Direct ac <- m[x] 0001XXXXXXXXXXXX stod Store Direct m[x] <- ac 0010XXXXXXXXXXXX addd Add Direct ac<- ac + m[x] 0011XXXXXXXXXXXX subd Subtract Direct ac <- ac - m[x] 0100XXXXXXXXXXXX jpos Jump on pos. IF ac>=0 : pc <- x 0101XXXXXXXXXXXX jzer Jump on zero IF ac=0 : pc <- x 0110XXXXXXXXXXXX jump Jump uncond. pc <- x (0 <= x <=4095) 0111CCCCCCCCCCCC loco Load constant ac <- c (0 <= c <=4095) --------------------------------------------------------------------
Appendix 1.2, Complete Mac-1 Instruction Set
Mnemonic Name Action(s)
-------- ---- ---------
lodd x Load Direct ac <- m[x]
stod x Store Direct m[x] <- ac
addd x Add Direct ac<- ac + m[x]
subd x Sub. Direct ac <- ac - m[x]
jpos x Jump on pos. IF ac>=0 : pc <- x
jzer x Jump on zero IF ac=0 : pc <- x
jump x Jump uncond. pc <- x (0 <= x <=4095)
loco c Load constant ac <- c (0<=c<=4095)
lodl x Load local ac <- m[sp+x]
stol x Store local m[sp+x] <- ac
addl x Add local ac <- ac + m[sp+x]
subl x Subtract local ac <- ac - m[sp+x]
jneg x Jump on negative if ac<0 : pc <- x
jnze x Jump on nonzero if ac!=0 : pc <- x
call x Call procedure sp<-sp-1; m[sp] <- pc; pc <- x
pshi Push indirect sp <- sp-1; m[sp]<-m[ac]
popi Pop indirect m[ac] <- m[sp]; sp <- sp+1
push Push onto stack sp <- sp-1; m[sp] <- ac
pop Pop off stack ac <- m[sp]; sp <- sp+1
retn Return from proc. pc <- m[sp]; sp <- sp + 1
swap Swap ac, pc temp <- ac; ac <- sp; sp<-temp
insp y Increment sp sp <- sp + y; (0 <= y <= 255)
desp y Decrement sp sp <- sp - y; (0 <= y <= 255)
Notes: 1. c is a constant in range 0 - 4095
2. x is an address in range 0 - 4095
3. y is an address offset in range 0 - 255
Appendix 2, Equivalences of Boolean Algebra