~grimmware/lc3

f122efa1272fa69d40d5d0006b383bc67489a63c — glenda 1 year, 2 months ago 7f63c80
Corrected byte packing for .STRINGZ string literals (hex literals are still incorrect)
1 files changed, 18 insertions(+), 11 deletions(-)

M asm.c
M asm.c => asm.c +18 -11
@@ 374,28 374,35 @@ parseline(char *l)
						inst->argc++;
						pc++;
					}
				} else if (l[0] == '"') {
				} else if (l[0] == '"'){
					l++;
					int parity = 0;
					gettoken(&t, l);
					if(t[strlen(t) - 1] != '"')
					int len = strlen(t);
					if(t[len - 1] != '"')
						syntaxerr("No closing quote");
					t++;
					for(int i = 0; i<(strlen(t) - 1); i++) {
						inst = newinst(OP_DATA);
						if(t[i] == '\\'){
					t[len - 1] = 0;
					for(int i=0; i<len; i++){
						if(t[i] == '\\' && t[i+1]){
							i++;
							parity = parity ? 0 : 1;
							switch(t[i]){
							case 'n':
								inst->p_arg[0] = '\n';
								t[i] = '\n';
								break;
							case 't':
								inst->p_arg[0] = '\t';
								t[i] = '\t';
								break;
							}
						}
						if(i % 2 == parity){
							inst = newinst(OP_DATA);
							inst->p_arg[0] = t[i];
						} else {
							inst->p_arg[0] = (u16int) t[i];
							inst->p_arg[0] |= t[i] << 8;
							inst->argc++;
							pc++;
						}
						inst->argc++;
						pc++;
					}
				} else {
					syntaxerr(".STRINGZ only supports hex and string literals");