Created
March 2, 2013 20:03
-
-
Save bitamar/5073035 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int add_operand_lines (char *operand, char *operand_offset, int work_on_src, int i, int line_num, int addr) { | |
switch (addr) { | |
case 0: | |
if ((!commands[i].src_imidiate_address && work_on_src) || (!commands[i].dest_imidiate_address && !work_on_src)) { | |
error_set("Error", "Illegal address.", line_num); | |
return 0; | |
} | |
IC++; | |
line_data = New(LineData); | |
line_data->decimal_address = IC; | |
line_data->label_to_extract = NULL; | |
commands_list = list_append(commands_list, line_data); | |
if((line_data->line_word.data = extract_number(&operand[1], line_num)) == 999999) | |
return 0; | |
break; | |
case 1: | |
if ((!commands[i].src_direct_address && work_on_src) || (!commands[i].dest_direct_address && !work_on_src)) { | |
error_set("Error", "Illegal address.", line_num); | |
return 0; | |
} | |
IC++; | |
line_data = New(LineData); | |
line_data->decimal_address = IC; | |
line_data->line_word.data = 0; | |
commands_list = list_append(commands_list, line_data); | |
line_data->label_to_extract = (char*)malloc(strlen(operand) + 1); | |
strcpy(line_data->label_to_extract, operand); | |
break; | |
case 2: | |
if ((!commands[i].src_index_address && work_on_src) || (!commands[i].dest_index_address && !work_on_src)) { | |
error_set("Error", "Illegal address.", line_num); | |
return 0; | |
} | |
IC++; | |
line_data = New(LineData); | |
line_data->decimal_address = IC; | |
line_data->line_word.data = 0; | |
commands_list = list_append(commands_list, line_data); | |
line_data->label_to_extract = (char*)malloc(strlen(operand) + 1); | |
strcpy(line_data->label_to_extract, operand); | |
if (isdigit(*operand_offset) || *operand_offset=='+' || *operand_offset=='-') { | |
IC++; | |
line_data = New(LineData); | |
line_data->decimal_address = IC; | |
line_data->label_to_extract = NULL; | |
commands_list = list_append(commands_list, line_data); | |
if((line_data->line_word.data = extract_number(operand_offset, line_num)) == 999999) { | |
error_set("Error", "Illegal address.", line_num); | |
return 0; | |
} | |
} | |
else if (!(*operand_offset == 'r' && strlen(operand_offset) == 2 && *(operand_offset + 1) >= '0' && *(operand_offset + 1) <= '7')) { | |
IC++; | |
line_data = New(LineData); | |
line_data->decimal_address = IC; | |
line_data->line_word.data = 0; | |
commands_list = list_append(commands_list, line_data); | |
line_data->label_to_extract = (char*)malloc(strlen(operand_offset) + 1); | |
strcpy(line_data->label_to_extract, operand_offset); | |
} | |
break; | |
case 3: | |
if ((!commands[i].src_direct_reg_address && work_on_src) || (!commands[i].dest_direct_reg_address && !work_on_src)) { | |
error_set("Error", "Illegal address.", line_num); | |
return 0; | |
} | |
break; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment