From f32304afb7b6deec3b81354f84ced54ac47a3976 Mon Sep 17 00:00:00 2001 From: EDiasAlberto Date: Wed, 12 Jun 2024 16:24:42 +0100 Subject: [PATCH 1/3] create helper function to generate number from operand --- src/parser.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/parser.c b/src/parser.c index 31b5ffc..97eef8d 100644 --- a/src/parser.c +++ b/src/parser.c @@ -18,6 +18,14 @@ // - ASK ABOUT OFFSET CALCULATION // - CREATE FUNC TO TIDY UP OPERANDS IN DP +int getOperandNumber(char *operand){ + char *operandCpy = strcpy(operandCpy, operand); + operandCpy++; + char **endptr; + int number = strtol(operandCpy, endptr, 10); + return number; +} + int isOperandRegister(char *operand){ return((strcmp(&(operand[0]), "x")==0) || (strcmp(&(operand[0]), "w")==0)); } @@ -161,6 +169,7 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[ //offset is literal, use symbol table and calculate difference } } + generateLoadStoreOperands(instr, opcode, operandList, numOperands); } else { if(classifyDPInst(operandList)){ From c6ff7e1c4e4405e10076a0335cb713250df0217f Mon Sep 17 00:00:00 2001 From: EDiasAlberto Date: Wed, 12 Jun 2024 16:29:29 +0100 Subject: [PATCH 2/3] comment getOperandNumber --- src/parser.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/parser.c b/src/parser.c index 97eef8d..cd7c9ed 100644 --- a/src/parser.c +++ b/src/parser.c @@ -18,6 +18,8 @@ // - ASK ABOUT OFFSET CALCULATION // - CREATE FUNC TO TIDY UP OPERANDS IN DP +//takes inputted char array and returns the integer of the operand, skipping the first character +//e.g. for a passed "R32", it skips the 'R' and returns 32 int getOperandNumber(char *operand){ char *operandCpy = strcpy(operandCpy, operand); operandCpy++; @@ -159,11 +161,7 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[ instr->type = a64inst_LOADLITERAL; if(operandList[0][0] =='#'){ //offset is immediate - char *immOffset = NULL; - immOffset = strcpy(immOffset, operandList[0]); - immOffset++; - char *endptr = NULL; - int offset = strtol(immOffset, &endptr, 10); + int offset = getOperandNumber(operandList[0]); instr->data.SingleTransferData.processOpData.loadLiteralData.offset = offset; } else { //offset is literal, use symbol table and calculate difference From f4fd71a33014d02ab4b29acd91666f00d9b19f35 Mon Sep 17 00:00:00 2001 From: EDiasAlberto Date: Wed, 12 Jun 2024 16:46:59 +0100 Subject: [PATCH 3/3] fix syntax error with getOperandNumber --- src/parser.c | 7 ++++--- test.sh | 0 2 files changed, 4 insertions(+), 3 deletions(-) mode change 100644 => 100755 test.sh diff --git a/src/parser.c b/src/parser.c index cd7c9ed..ba29ccf 100644 --- a/src/parser.c +++ b/src/parser.c @@ -21,9 +21,10 @@ //takes inputted char array and returns the integer of the operand, skipping the first character //e.g. for a passed "R32", it skips the 'R' and returns 32 int getOperandNumber(char *operand){ - char *operandCpy = strcpy(operandCpy, operand); + char *operandCpy = NULL; + strcpy(operandCpy, operand); operandCpy++; - char **endptr; + char **endptr = NULL; int number = strtol(operandCpy, endptr, 10); return number; } @@ -74,7 +75,6 @@ void generateLoadStoreOperands(a64inst_instruction *instr, char *opcode, char *o } char *endptr; instr->data.SingleTransferData.target = strtol(&(operandList[0][0])+1, &endptr, 10); - calcluateAddressFormat(instr, operandList, numOperands); break; case a64inst_LOADLITERAL: break; @@ -242,6 +242,7 @@ void parser_instruction(char asmLine[], a64inst_instruction *instr) { break; case a64inst_SINGLETRANSFER: generateLoadStoreOperands(instr, opcode, operandList, numOperands); + calcluateAddressFormat(instr, operandList, numOperands); break; case a64inst_LOADLITERAL: generateLoadStoreOperands(instr, opcode, operandList, numOperands); diff --git a/test.sh b/test.sh old mode 100644 new mode 100755