Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Shen, Siran
arm11_
Commits
503124ce
Commit
503124ce
authored
Jun 18, 2020
by
sea19
Browse files
Christopher's extension should be working as well
parent
9774518a
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/assemble_utils.c
View file @
503124ce
...
...
@@ -5,10 +5,13 @@
#include "macrosAndStructs.h"
static
const
char
*
mnemonicsList
[]
=
{
"add"
,
"sub"
,
"rsb"
,
"and"
,
"eor"
,
"orr"
,
"mov"
,
"tst"
,
"teq"
,
"cmp"
,
"mul"
,
"mla"
,
"ldr"
,
"str"
,
"beq"
,
"bne"
,
"bge"
,
"blt"
,
"bgt"
,
"ble"
,
"b"
,
"lsl"
,
"andeq"
"add"
,
"sub"
,
"rsb"
,
"and"
,
"eor"
,
"orr"
,
"mov"
,
"tst"
,
"teq"
,
"cmp"
,
"mul"
,
"mla"
,
"ldr"
,
"str"
,
"beq"
,
"bne"
,
"bge"
,
"blt"
,
"bgt"
,
"ble"
,
"b"
,
"bleq"
,
"blne"
,
"blge"
,
"bllt"
,
"blgt"
,
"blle"
,
"bl"
,
//extension instruction set
"lsl"
,
"andeq"
,
"swi"
,
"bx"
,
"swp"
,
"swpb"
//swi, bx, swp, swpb - extension instructions
};
int
findLabel
(
FILE
*
srcFile
,
char
*
label
,
int
currentAddress
)
{
int
i
=
0
;
char
*
buffer
=
calloc
(
MAX_LENGTH_OF_LINE
,
sizeof
(
char
));
...
...
@@ -75,6 +78,9 @@ int generateBinary(char *buffer, int *storedValues, int currentAddress, int noOf
char
*
sep
=
" ,"
,
*
token
=
strtok
(
buffer
,
sep
),
operands
[
6
][
20
];
memset
(
operands
,
0
,
sizeof
(
operands
));
int
mnemonic
=
findMnemonic
(
token
),
noOperands
=
0
;
if
(
mnemonic
==
-
1
)
{
return
UNDEFINED
;
}
while
(
token
!=
NULL
)
{
token
=
strtok
(
NULL
,
sep
);
if
(
token
)
{
...
...
@@ -91,12 +97,16 @@ int generateBinary(char *buffer, int *storedValues, int currentAddress, int noOf
if
(
mnemonic
<
BEQ
)
{
return
assembleSingleDataTransfer
(
mnemonic
,
operands
,
storedValues
,
noOfInstructions
,
currentAddress
);
}
if
(
mnemonic
<
LSLOP
)
{
if
(
mnemonic
<
BLEQ
)
{
return
assembleBranch
(
mnemonic
,
operands
,
srcFile
,
currentAddress
);
}
if
(
mnemonic
<
LSL
)
{
return
assembleBranchLink
(
mnemonic
,
operands
,
srcFile
,
currentAddress
);
}
return
assembleSpecial
(
mnemonic
,
operands
);
}
int
findMnemonic
(
char
*
p
)
{
int
i
;
for
(
i
=
0
;
i
<
NUM_OF_MNENMONICS
;
i
++
)
{
...
...
@@ -357,13 +367,76 @@ int assembleBranch(enum mnemonics mnemonic, char operands[6][20], FILE *srcFile,
return
result
;
}
int
assembleBranchLink
(
enum
mnemonics
mnemonic
,
char
operands
[
6
][
20
],
FILE
*
srcFile
,
int
currentAddress
)
{
//extension instruction set
int
result
=
0
;
if
(
mnemonic
>=
BLEQ
&&
mnemonic
<=
BL
)
{
switch
(
mnemonic
)
{
case
BLEQ
:
result
=
assembleBranch
(
BEQ
,
operands
,
srcFile
,
currentAddress
);
break
;
case
BLNE
:
result
=
assembleBranch
(
BNE
,
operands
,
srcFile
,
currentAddress
);
break
;
case
BLGE
:
result
=
assembleBranch
(
BGE
,
operands
,
srcFile
,
currentAddress
);
break
;
case
BLLT
:
result
=
assembleBranch
(
BLT
,
operands
,
srcFile
,
currentAddress
);
break
;
case
BLGT
:
result
=
assembleBranch
(
BGT
,
operands
,
srcFile
,
currentAddress
);
break
;
case
BLLE
:
result
=
assembleBranch
(
BLE
,
operands
,
srcFile
,
currentAddress
);
break
;
case
BL
:
result
=
assembleBranch
(
B
,
operands
,
srcFile
,
currentAddress
);
break
;
default:
printf
(
"Invalid mnemonic"
);
}
}
setBitAtPos
(
24
,
1
,
&
result
);
return
result
;
}
int
assembleSpecial
(
enum
mnemonics
mnemonic
,
char
operands
[
6
][
20
])
{
if
(
mnemonic
==
ANDEQ
)
{
return
0
;
int
result
=
0
,
cond
=
COND_AL
,
mask
,
rn
;
switch
(
mnemonic
)
{
case
SWI
:
//extension instruction
mask
=
15
;
// 1111
setBitAtPos
(
COND_BIT
,
cond
,
&
result
);
setBitAtPos
(
24
,
mask
,
&
result
);
return
result
;
case
BX
:
//extension instruction
mask
=
1245169
,
rn
=
atoi
(
operands
[
0
]
+
1
);
//100101111111111110001
setBitAtPos
(
COND_BIT
,
cond
,
&
result
);
setBitAtPos
(
4
,
mask
,
&
result
);
setBitAtPos
(
0
,
rn
,
&
result
);
return
result
;
case
LSL
:
strcpy
(
operands
[
3
],
operands
[
1
]);
strcpy
(
operands
[
1
],
operands
[
0
]);
strcpy
(
operands
[
2
],
"lsl"
);
return
assembleDataProcessing
(
MOV
,
operands
);
case
ANDEQ
:
return
0
;
case
SWP
:
//extension instruction
mask
=
9
,
rn
=
atoi
(
operands
[
2
]
+
2
);
//1001
int
rd
=
atoi
(
operands
[
0
]
+
1
),
rm
=
atoi
(
operands
[
1
]
+
1
);
setBitAtPos
(
COND_BIT
,
cond
,
&
result
);
setBitAtPos
(
0
,
rm
,
&
result
);
setBitAtPos
(
12
,
rd
,
&
result
);
setBitAtPos
(
16
,
rn
,
&
result
);
setBitAtPos
(
4
,
mask
,
&
result
);
setBitAtPos
(
24
,
1
,
&
result
);
return
result
;
case
SWPB
:
//extension instruction
result
=
assembleSpecial
(
SWP
,
operands
);
setBitAtPos
(
22
,
1
,
&
result
);
return
result
;
default:
printf
(
"Invalid mnemonic"
);
return
result
;
}
strcpy
(
operands
[
3
],
operands
[
1
]);
strcpy
(
operands
[
1
],
operands
[
0
]);
strcpy
(
operands
[
2
],
"lsl"
);
return
assembleDataProcessing
(
MOV
,
operands
);
}
src/assemble_utils.h
View file @
503124ce
...
...
@@ -2,10 +2,17 @@
#define ASSEMBLE_UTILS_H
#include <stdio.h>
static
const
int
undefined
=
-
436207600
;
//11100110000000000000000000010000
enum
mnemonics
{
ADD
,
SUB
,
RSB
,
AND
,
EOR
,
ORR
,
MOV
,
TST
,
TEQ
,
CMP
,
MUL
,
MLA
,
LDR
,
STR
,
BEQ
,
BNE
,
BGE
,
BLT
,
BGT
,
BLE
,
B
,
LSLOP
,
ANDEQ
ADD
,
SUB
,
RSB
,
AND
,
EOR
,
ORR
,
MOV
,
TST
,
TEQ
,
CMP
,
MUL
,
MLA
,
LDR
,
STR
,
BEQ
,
BNE
,
BGE
,
BLT
,
BGT
,
BLE
,
B
,
BLEQ
,
BLNE
,
BLGE
,
BLLT
,
BLGT
,
BLLE
,
BL
,
//extension instruction set
LSL
,
ANDEQ
,
SWI
,
BX
,
SWP
,
SWPB
,
UNDEFINED
//swi, bx, swp, swpb - extension instructions
};
int
findLabel
(
FILE
*
srcFile
,
char
*
label
,
int
currentAddress
);
int
getNoOfInstructions
(
FILE
*
srcFile
);
...
...
@@ -24,6 +31,8 @@ int assembleSingleDataTransfer(enum mnemonics mnemonic, char operands[6][20], in
int
assembleBranch
(
enum
mnemonics
mnemonic
,
char
operands
[
6
][
20
],
FILE
*
srcFile
,
int
currentAddress
);
int
assembleBranchLink
(
enum
mnemonics
mnemonic
,
char
operands
[
6
][
20
],
FILE
*
srcFile
,
int
currentAddress
);
int
assembleSpecial
(
enum
mnemonics
mnemonic
,
char
operands
[
6
][
20
]);
int
checkBit
(
int
pos
,
int
number
);
...
...
src/macrosAndStructs.h
View file @
503124ce
...
...
@@ -34,7 +34,7 @@
#define COND_BIT 28
#define MAX_LENGTH_OF_LINE 511
#define PC_OFFSET 8
#define NUM_OF_MNENMONICS
2
3
#define NUM_OF_MNENMONICS 3
4
#define MAX_LDR_USED_AS_MOV 256
#define MAX_NO_OF_ROTATIONS 16
#define ONE_ROTATION 2
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment