I am trying to create a truth table for the function F=(A&B) XOR (C&D’). I’m using Intel assembly language and the whole code has to be fairly short.
The main problem that I keep running into is with the loop to manipulate the variables A,B,C and D to create all the possible inputs of a truth table. The way this would be typically done is to act like the variables are each a bit of a 4 bit binary number and count from 0 to 15, implementing each possible input. I only have 4 registers a stack and RAM memory to accomplish this so I assigned each variable to a register, and I use ram to store a counter and the outputs of the table. I can’t think of a good way to do this with a loop, but I have to use one because the simulator I’m using won’t function with code as long as mine has become. (It’s 256 bytes)
Here is the code, the subroutine called procedure 60 is the piece I want to condense. I don’t have to actually output a truth table just tell how many “Minterm’s” (outputs of 1) are produced by it.
;MAIN
MOV AL,0 ;INITIALIZING VARIABLES
MOV BL,0
MOV CL,0
MOV DL,0
MOV [20],AL ;INITIALIZE CURRENT NUMBER OF MINTERMS WITH 0
MOV [21],AL ;INITIALIZE COUNTER WITH 0
LOOP: CALL 30
CALL 60
MOV [21],CL
CMP CL,15
JS LOOP
CALL E0
MOV AL,[20] ;MOVE NUMBER OF MINTERMS TO AL
MOV [FF],AL ;OUPUT NUMBER OF MINTERMS TO VDU(LOCATIONS [C0] TO [FF])
;PROCEDURE 30, IMPLEMENTS THE GIVEN BOOLEAN FUNCTION
ORG 30 ;WRITE CODE BEGINNING AT [30]
PUSH DL ;CURRENT VALUE OF D
PUSH CL ;CURRENT VALUE OF C
PUSH AL ;CURRENT VALUE OF A, IMPLEMENTING FUNCTION WON'T CHANGE D
AND AL,BL ;PERFORMS (AL AND BL), STORES VALUE IN AL
NOT DL ;INVERSE OF DL STORED IN DL
AND CL,DL ;PERFORMS (CL AND DL), STORES VALUE IN CL
XOR AL,CL ;PERFORMS (AL XOR CL), STORES VALUE IN AL
MOV BL,[20] ;MOVES CURRENT NUMBER OF MINTERMS TO BL
ADD AL,BL ;ADD TO CURRENT NUMBER OF MINTERMS IF MINTERM RESULTED FROM FUNCTION
MOV [20],AL ;STORE NEW CURRENT NUMBER OF MINTERMS
MOV CL,[21] ;MOVE COUNTER TO CL
INC CL ;INCREMENT CL, INCREMENTING COUNTER
MOV [21],CL ;MOVE NEW VALUE OF COUNTER
POP AL ;RESTORE PREVIOUS VALUE OF D
POP CL ;RESTORE PREVIOUS VALUE OF C
POP DL ;RESTORE PREVIOUS VALUE OF A
RET
;PROCEDURE 60, MANIPULATES VARIABLES TO IMPLEMENT FULL TRUTH TABLE
ORG 60 ;WRITE CODE BEGINNING AT [60]
MOV CL,[21] ;MOVE COUNTER VALUE TO CL REGISTER
CMP CL,1 ;NEED TO MAKE THIS INTO A LOOP
JZ FIRST
CMP CL,2
JZ SECOND
CMP CL,3
JZ FIRST
CMP CL,4
JZ FOURTH
CMP CL,5
JZ FIRST
CMP CL,6
JZ SECOND
CMP CL,7
JZ FIRST
CMP CL,8
JZ EIGHTH
CMP CL,9
JZ FIRST
CMP CL,10
JZ SECOND
CMP CL,11
JZ FIRST
CMP CL,12
JZ FOURTH
CMP CL,13
JZ FIRST
CMP CL,14
JZ SECOND
CMP CL,15
JZ FIRST
JMP LAST
FIRST:
MOV AL,1
JMP LAST
SECOND:
MOV AL,0
MOV BL,1
JMP LAST
FOURTH:
MOV AL,0
MOV BL,0
MOV CL,1
JMP LAST
EIGHTH:
MOV AL,0
MOV BL,0
MOV CL,0
MOV DL,1
JMP LAST
LAST:
RET
FINISH:
ORG E0 ;WRITE CODE BEGINNING AT E0(OUTPUTS TO VDU)
DB "The number of Minterms in F is" ;OUTPUT STATEMENT
RET
END
How about simply: