Skip to content

Commit

Permalink
2.3.0: minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
acaldero committed Aug 23, 2023
1 parent 15d9f54 commit a0eb4dc
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 105 deletions.
2 changes: 1 addition & 1 deletion repo/assembly/mips/s4e1.asm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ sys_print: li $0 0

li $t0 0
li $t1 1
li $t2 100
li $t2 80
b1: beq $t0 $t2 e1
add $t0 $t0 $t1
b b1
Expand Down
2 changes: 1 addition & 1 deletion repo/assembly/mips/s4e1_help.asm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ sys_print: li $0 0

li $t0 0
li $t1 1
li $t2 100
li $t2 80
b1: beq $t0 $t2 e1
add $t0 $t0 $t1
b b1
Expand Down
2 changes: 1 addition & 1 deletion repo/checkpoint/tutorial_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
{
"cell_type": "code",
"source": "\n#\n# WepSIM (https://wepsim.github.io/wepsim/)\n#\n\n.kdata\n vector: .word rt_i0\n .word rt_div0\n .word rt_sys\n\n msgi0: .asciiz \"INT: 0\\n\"\n msgi1: .asciiz \"FPE: */0\\n\"\n\n.ktext\nsys_print: li $0 0\n li $1 1\n beq $26 $0 fin1\n b5: lb $27 ($26)\n beq $27 $0 fin1\n out $27 0x1000\n add $26 $26 $1\n b b5\n fin1: reti\n\n rt_i0: # 1.- interruption\n la $26 msgi0\n b sys_print\n\n rt_div0: # 2.- exception\n la $26 msgi1\n b sys_print\n\n rt_sys: # 3.- syscall\n move $26 $a0\n li $27 4\n beq $v0 $27 sys_print\n reti \n\n\n.data\n helloworld: .asciiz \"hello world...\\n\"\n\n.text\n main: # test syscall\n la $a0 helloworld\n li $v0 4\n syscall\n\n # test div 0/0\n li $t0 0\n li $t1 0\n div $t1 $t1 $t0\n\n # test int0\n li $t0 0\n out $t0 0x1104\n li $t0 900\n out $t0 0x1108\n\n li $t0 0\n li $t1 1\n li $t2 100\n b1: beq $t0 $t2 e1\n add $t0 $t0 $t1\n b b1\n\n e1: li $t0 0\n out $t0 0x1104\n out $t0 0x1108\n\n # the end\n jr $ra\n\n",
"source": "\n#\n# WepSIM (https://wepsim.github.io/wepsim/)\n#\n\n.kdata\n vector: .word rt_i0\n .word rt_div0\n .word rt_sys\n\n msgi0: .asciiz \"INT: 0\\n\"\n msgi1: .asciiz \"FPE: */0\\n\"\n\n.ktext\nsys_print: li $0 0\n li $1 1\n beq $26 $0 fin1\n b5: lb $27 ($26)\n beq $27 $0 fin1\n out $27 0x1000\n add $26 $26 $1\n b b5\n fin1: reti\n\n rt_i0: # 1.- interruption\n la $26 msgi0\n b sys_print\n\n rt_div0: # 2.- exception\n la $26 msgi1\n b sys_print\n\n rt_sys: # 3.- syscall\n move $26 $a0\n li $27 4\n beq $v0 $27 sys_print\n reti \n\n\n.data\n helloworld: .asciiz \"hello world...\\n\"\n\n.text\n main: # test syscall\n la $a0 helloworld\n li $v0 4\n syscall\n\n # test div 0/0\n li $t0 0\n li $t1 0\n div $t1 $t1 $t0\n\n # test int0\n li $t0 0\n out $t0 0x1104\n li $t0 900\n out $t0 0x1108\n\n li $t0 0\n li $t1 1\n li $t2 80\n b1: beq $t0 $t2 e1\n add $t0 $t0 $t1\n b b1\n\n e1: li $t0 0\n out $t0 0x1104\n out $t0 0x1108\n\n # the end\n jr $ra\n\n",
"outputs": [],
"execution_count": 1,
"metadata": {
Expand Down
12 changes: 6 additions & 6 deletions sim_core/sim_adt_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@
mp: {},
seg: {},
labels: {},
labels2: {},
labels_asm: {},
labels_firm: {},
registers: {},
pseudoInstructions: [],
stackRegister: null,

// auxiliar datatypes
hash_ci: {},
hash_cocop: {},
hash_labels_rev: {},
hash_labels2_rev: {},
hash_seg_rev: []
hash_ci: {},
hash_cocop: {},
hash_labels_firm_rev: {},
hash_labels_asm_rev: {},
hash_seg_rev: []
} ;


Expand Down
12 changes: 6 additions & 6 deletions sim_core/sim_api_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@
var SIMWARE = get_simware();

if (
(! ((typeof curr_segments['.ktext'] != "undefined") && (SIMWARE.labels2.kmain)) ) &&
(! ((typeof curr_segments['.text'] != "undefined") && (SIMWARE.labels2.main)) )
(! ((typeof curr_segments['.ktext'] != "undefined") && (SIMWARE.labels_asm.kmain)) ) &&
(! ((typeof curr_segments['.text'] != "undefined") && (SIMWARE.labels_asm.main)) )
)
{
ret.msg = "labels 'kmain' (in .ktext) or 'main' (in .text) do not exist!" ;
Expand Down Expand Up @@ -396,14 +396,14 @@
}

// CPU registers initial values
if ((typeof curr_segments['.ktext'] !== "undefined") && (SIMWARE.labels2.kmain))
if ((typeof curr_segments['.ktext'] !== "undefined") && (SIMWARE.labels_asm.kmain))
{
set_value(pc_state, parseInt(SIMWARE.labels2.kmain)) ;
set_value(pc_state, parseInt(SIMWARE.labels_asm.kmain)) ;
show_asmdbg_pc() ;
}
else if ((typeof curr_segments['.text'] !== "undefined") && (SIMWARE.labels2.main))
else if ((typeof curr_segments['.text'] !== "undefined") && (SIMWARE.labels_asm.main))
{
set_value(pc_state, parseInt(SIMWARE.labels2.main)) ;
set_value(pc_state, parseInt(SIMWARE.labels_asm.main)) ;
show_asmdbg_pc() ;
}

Expand Down
44 changes: 27 additions & 17 deletions sim_sw/assembly/asm_ng.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function wsasm_src2obj_data ( context, ret )
i18n_get_TagFor('compiler', 'TAG OR INSTRUCTION') +
"'" + tag + "'") ;
}
if (ret.labels2[tag]) {
if (ret.labels_asm[tag]) {
return asm_langError(context,
i18n_get_TagFor('compiler', 'REPEATED TAG') +
"'" + tag + "'") ;
Expand Down Expand Up @@ -601,6 +601,7 @@ function wsasm_src2obj_data ( context, ret )
elto.track_source.push('0x0') ;
}
elto.byte_size = elto.value.length ;
elto.source = possible_value ;

ret.obj.push(elto) ;
elto = wsasm_new_objElto(elto) ;
Expand Down Expand Up @@ -833,6 +834,8 @@ function wsasm_find_instr_candidates ( context, ret, elto )
elto.value.signature_user + ".<br>" +
i18n_get_TagFor('compiler', 'CHECK MICROCODE') ;

// TODO: add the list of available candidates (if any) to help students to match its instructions...

return asm_langError(context, msg) ;
}

Expand Down Expand Up @@ -1171,7 +1174,7 @@ function wsasm_src2obj_text ( context, ret )
i18n_get_TagFor('compiler', 'TAG OR INSTRUCTION') +
"'" + tag + "'") ;
}
if (ret.labels2[tag]) {
if (ret.labels_asm[tag]) {
return asm_langError(context,
i18n_get_TagFor('compiler', 'REPEATED TAG') +
"'" + tag + "'") ;
Expand Down Expand Up @@ -1377,8 +1380,9 @@ function wsasm_resolve_pseudo ( context, ret )
return ret ;
}

if (0 == eltos.length)
if (0 == eltos.length) {
elto.labels = pseudo_elto.labels ;
}

// add elto to some temporal array
eltos.push(elto) ;
Expand Down Expand Up @@ -1440,10 +1444,10 @@ function wsasm_compute_labels ( context, ret, start_at_obj_i )
ret.obj[i].byte_offset = elto_ptr - seg_ptr ; // offset within .data segment
ret.obj[i].padding = 0 ;

// add labels2...
// add labels_asm...
for (var j=0; j<ret.obj[i].labels.length; j++) {
tag = ret.obj[i].labels[j] ;
ret.labels2[tag] = "0x" + elto_ptr.toString(16) ;
ret.labels_asm[tag] = "0x" + elto_ptr.toString(16) ;
}

// machine_code and total size...
Expand All @@ -1470,7 +1474,7 @@ function wsasm_get_label_value ( context, ret, label )
var valbin = '' ;

// if label -> return associated value as integer
value = ret.labels2[label] ;
value = ret.labels_asm[label] ;
if (typeof value !== "undefined")
{
valbin = (parseInt(value) >>> 0).toString(2) ;
Expand All @@ -1494,7 +1498,7 @@ function wsasm_get_label_value ( context, ret, label )
var sel_label = value_arr[1] ;

// if label not found -> return error
value = ret.labels2[sel_label] ;
value = ret.labels_asm[sel_label] ;
if (typeof value === "undefined")
{
return asm_langError(context,
Expand Down Expand Up @@ -1620,9 +1624,9 @@ function wsasm_resolve_labels ( context, ret )
}
}

// build reverse lookup hash labels (hash labels2 -> key)
for (var key in ret.labels2) {
ret.hash_labels2_rev[ret.labels2[key]] = key ;
// build reverse lookup hash labels (hash labels_asm -> key)
for (var key in ret.labels_asm) {
ret.hash_labels_asm_rev[ret.labels_asm[key]] = key ;
}

// build reverse lookup hash segments (hash segname -> properties)
Expand Down Expand Up @@ -1780,12 +1784,12 @@ function wsasm_src2obj ( context )
var ret = {} ;
ret.obj = [] ;
ret.mp = {} ;
ret.seg = sim_segments ;
ret.hash_seg_rev = [] ;
ret.labels2 = {} ;
ret.hash_labels2_rev = {} ;
ret.labels = {} ; // [addr] = {name, addr, startbit, stopbit}
ret.labels_valbin = {} ;
ret.seg = sim_segments ;
ret.hash_seg_rev = [] ;
ret.labels_asm = {} ;
ret.hash_labels_asm_rev = {} ;
ret.labels = {} ; // [addr] = {name, addr, startbit, stopbit}
ret.labels_valbin = {} ;

// Check arguments
if (typeof context == "undefined") {
Expand Down Expand Up @@ -1848,13 +1852,19 @@ function wsasm_obj2mem ( ret )
seg_name_old = seg_name ;
}

// ...and update initial word address for this segment if needed...
// ...update initial word address for this segment if needed...
if (typeof last_assig_word[seg_name] == "undefined")
{
gen.addr = "0x" + ret.obj[i].elto_ptr.toString(16) ;
last_assig_word[seg_name] = gen.addr ;
}

// ... and setup the working address for the new obj[i]
gen.addr = last_assig_word[seg_name] ; // recover last saved value if we switch to other segment
if ((ret.obj[i].elto_ptr / WORD_BYTES) > (parseInt(gen.addr) / WORD_BYTES)) {
wsasm_zeropadding_and_writememory(ret.mp, gen) ;
gen.addr = "0x" + ret.obj[i].elto_ptr.toString(16) ;
}

// (2) if .align X then address of next elto must be multiple of 2^X
if (wsasm_has_datatype_attr(ret.obj[i].datatype, "align"))
Expand Down
32 changes: 16 additions & 16 deletions sim_sw/assembly/asm_v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ function read_data ( context, datosCU, ret )
i18n_get_TagFor('compiler', 'TAG OR INSTRUCTION') +
"'" + tag + "'") ;
}
if (ret.labels2[tag]) {
if (ret.labels_asm[tag]) {
return asm_langError(context,
i18n_get_TagFor('compiler', 'REPEATED TAG') +
"'" + tag + "'") ;
}

// Store tag
ret.labels2[tag] = "0x" + (gen.seg_ptr+gen.byteWord).toString(16);
ret.labels_asm[tag] = "0x" + (gen.seg_ptr+gen.byteWord).toString(16);

// .<datatype> | tagX+1
asm_nextToken(context) ;
Expand Down Expand Up @@ -352,7 +352,7 @@ function read_data ( context, datosCU, ret )

// Store tag
if ("" != possible_tag) {
ret.labels2[possible_tag.substring(0, possible_tag.length-1)] = "0x" + (gen.seg_ptr+gen.byteWord).toString(16) ;
ret.labels_asm[possible_tag.substring(0, possible_tag.length-1)] = "0x" + (gen.seg_ptr+gen.byteWord).toString(16) ;
possible_tag = "" ;
}

Expand Down Expand Up @@ -681,14 +681,14 @@ function read_text ( context, datosCU, ret )
i18n_get_TagFor('compiler', 'TAG OR INSTRUCTION') +
"'" + tag + "'") ;
}
if (ret.labels2[tag]) {
if (ret.labels_asm[tag]) {
return asm_langError(context,
i18n_get_TagFor('compiler', 'REPEATED TAG') +
"'" + tag + "'") ;
}

// store tag
ret.labels2[tag] = "0x" + seg_ptr.toString(16);
ret.labels_asm[tag] = "0x" + seg_ptr.toString(16);

asm_nextToken(context);
}
Expand Down Expand Up @@ -1333,12 +1333,12 @@ function simlang_compile_v1 (text, datosCU)
}

var ret = {};
ret.seg = sim_segments ;
ret.mp = {} ;
ret.labels = {} ; // [addr] = {name, addr, startbit, stopbit}
ret.labels2 = {} ;
ret.hash_labels2_rev = {} ;
ret.hash_seg_rev = [] ;
ret.seg = sim_segments ;
ret.hash_seg_rev = [] ;
ret.labels = {} ; // [addr] = {name, addr, startbit, stopbit}
ret.labels_asm = {} ;
ret.hash_labels_asm_rev = {} ;

data_found = false;
text_found = false;
Expand Down Expand Up @@ -1379,7 +1379,7 @@ function simlang_compile_v1 (text, datosCU)
for (i in ret.labels)
{
// Get label value (address number)
var value = ret.labels2[ret.labels[i].name];
var value = ret.labels_asm[ret.labels[i].name];

// Check if the label exists
if (typeof value === "undefined") {
Expand Down Expand Up @@ -1476,17 +1476,17 @@ function simlang_compile_v1 (text, datosCU)
// check if main or kmain in assembly code
if (text_found)
{
if ( (typeof ret.labels2["main"] === "undefined" ) &&
(typeof ret.labels2["kmain"] === "undefined" ) )
if ( (typeof ret.labels_asm["main"] === "undefined" ) &&
(typeof ret.labels_asm["kmain"] === "undefined" ) )
{
return asm_langError(context,
i18n_get_TagFor('compiler', 'NO MAIN OR KMAIN')) ;
}
}

// reverse labels (hash labels2 -> key)
for (var key in ret.labels2) {
ret.hash_labels2_rev[ret.labels2[key]] = key ;
// reverse labels (hash labels_asm -> key)
for (var key in ret.labels_asm) {
ret.hash_labels_asm_rev[ret.labels_asm[key]] = key ;
}

// reverse segments (hash segname -> properties)
Expand Down
34 changes: 17 additions & 17 deletions sim_sw/assembly/asm_v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ function read_data_v2 ( context, datosCU, ret )
i18n_get_TagFor('compiler', 'TAG OR INSTRUCTION') +
"'" + tag + "'") ;
}
if (ret.labels2[tag]) {
if (ret.labels_asm[tag]) {
return asm_langError(context,
i18n_get_TagFor('compiler', 'REPEATED TAG') +
"'" + tag + "'") ;
}

// Store tag
ret.labels2[tag] = "0x" + (gen.seg_ptr+gen.byteWord).toString(16);
ret.labels_asm[tag] = "0x" + (gen.seg_ptr+gen.byteWord).toString(16);

// .<datatype> | tagX+1
asm_nextToken(context) ;
Expand Down Expand Up @@ -256,7 +256,7 @@ function read_data_v2 ( context, datosCU, ret )

// Store tag
if ("" != possible_tag) {
ret.labels2[possible_tag.substring(0, possible_tag.length-1)] = "0x" + (gen.seg_ptr+gen.byteWord).toString(16) ;
ret.labels_asm[possible_tag.substring(0, possible_tag.length-1)] = "0x" + (gen.seg_ptr+gen.byteWord).toString(16) ;
possible_tag = "" ;
}

Expand Down Expand Up @@ -585,14 +585,14 @@ function read_text_v2 ( context, datosCU, ret )
i18n_get_TagFor('compiler', 'TAG OR INSTRUCTION') +
"'" + tag + "'") ;
}
if (ret.labels2[tag]) {
if (ret.labels_asm[tag]) {
return asm_langError(context,
i18n_get_TagFor('compiler', 'REPEATED TAG') +
"'" + tag + "'") ;
}

// store tag
ret.labels2[tag] = "0x" + seg_ptr.toString(16);
ret.labels_asm[tag] = "0x" + seg_ptr.toString(16);

asm_nextToken(context);
}
Expand Down Expand Up @@ -1275,12 +1275,12 @@ function simlang_compile_v2 (text, datosCU)
}

var ret = {};
ret.seg = sim_segments ;
ret.mp = {} ;
ret.labels = {} ; // [addr] = {name, addr, startbit, stopbit}
ret.labels2 = {} ;
ret.hash_labels2_rev = {} ;
ret.hash_seg_rev = [] ;
ret.mp = {} ;
ret.seg = sim_segments ;
ret.hash_seg_rev = [] ;
ret.labels_asm = {} ;
ret.hash_labels_asm_rev = {} ;
ret.labels = {} ; // [addr] = {name, addr, startbit, stopbit}

data_found = false;
text_found = false;
Expand Down Expand Up @@ -1321,7 +1321,7 @@ function simlang_compile_v2 (text, datosCU)
for (i in ret.labels)
{
// Get label value (address number)
var value = ret.labels2[ret.labels[i].name];
var value = ret.labels_asm[ret.labels[i].name];

// Check if the label exists
if (typeof value === "undefined") {
Expand Down Expand Up @@ -1419,17 +1419,17 @@ function simlang_compile_v2 (text, datosCU)
// check if main or kmain in assembly code
if (text_found)
{
if ( (typeof ret.labels2["main"] === "undefined" ) &&
(typeof ret.labels2["kmain"] === "undefined" ) )
if ( (typeof ret.labels_asm["main"] === "undefined" ) &&
(typeof ret.labels_asm["kmain"] === "undefined" ) )
{
return asm_langError(context,
i18n_get_TagFor('compiler', 'NO MAIN OR KMAIN')) ;
}
}

// reverse labels (hash labels2 -> key)
for (var key in ret.labels2) {
ret.hash_labels2_rev[ret.labels2[key]] = key ;
// reverse labels (hash labels_asm -> key)
for (var key in ret.labels_asm) {
ret.hash_labels_asm_rev[ret.labels_asm[key]] = key ;
}

// reverse segments (hash segname -> properties)
Expand Down
Loading

0 comments on commit a0eb4dc

Please sign in to comment.