-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiply.c
46 lines (41 loc) · 1.54 KB
/
multiply.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "multiply.h"
/**
* Generates the binary encoding of the given multiply instruction
* @param instruction 32 bit instruction
* @param address Keeps track of the current address of the instruction
* @return Binary format of the given instruction
*/
uint32_t generalMulAssembler(char *instruction, uint32_t address) {
char *destReg = strtok(instruction, ",");
uint32_t destRegIdx = readRegisterIndex(destReg);
char *regM = strtok(NULL, ",");
uint32_t regMIdx = readRegisterIndex(regM);
char *regS = strtok(NULL, ",");
uint32_t regSIdx = readRegisterIndex(regS);
instr = MUL_INSTR + (destRegIdx << DESTREG_START) + (regSIdx << REGS_START)
+ (regMIdx << REGM_START);
return instr;
}
/**
* Calls the generalMulAssembler function if the accumulate bit is not set
* @param instruction 32 bit instruction
* @param address Current address of the instruction
* @return Binary format of the given instruction
*/
uint32_t mulAssembler(char *instruction, uint32_t address) {
return generalMulAssembler(instruction, address);
}
/**
* Executes the multiply instruction when the accumulate bit is to be set
* @param instruction 32 bit instruction
* @param address Current address of the instruction
* @return Binary format of the given instruction
*/
uint32_t mlaAssembler(char *instruction, uint32_t address) {
instr = generalMulAssembler(instruction, address);
instr = instr | generateMask(ACC, 1);
char *regN = strtok(NULL, ",");
uint32_t regNIdx = readRegisterIndex(regN);
instr += (regNIdx << REGN_START);
return instr;
}