Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Added sp handling to MOVE instruction, and rudimentary handling of JMP/JSR operands. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
8fa71e963beaa8ac3ad59561e5c45bcc |
User & Date: | jos 2015-07-31 14:02:14.194 |
Context
2015-07-31
| ||
22:06 | Eliminated all the print-statements from 'opcodes.lua', Cleanup of the list-file output. check-in: 8a5653ef25 user: jos tags: trunk | |
14:02 | Added sp handling to MOVE instruction, and rudimentary handling of JMP/JSR operands. check-in: 8fa71e963b user: jos tags: trunk | |
2015-07-30
| ||
16:10 | A picture says more than 0x3e8 words :-) Added a drawing to illustrate the relations between the MegaProcessor's registers. check-in: cb73d9315a user: jos tags: trunk | |
Changes
Changes to asm.lua.
︙ | ︙ | |||
18 19 20 21 22 23 24 | function ProcessFile( inFileName ) local inFile = Check( io.open(inFileName,"r"), "Can't open file " .. inFileName ); local LineNr = 1; for l in inFile:lines() do | | > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | function ProcessFile( inFileName ) local inFile = Check( io.open(inFileName,"r"), "Can't open file " .. inFileName ); local LineNr = 1; for l in inFile:lines() do io.write( string.format("%04d ", LineNr) ); ProcessLine( l ); LineNr = LineNr + 1; end end function Fields( line ) if( line == "" or line:match("^%s*//") ) then return 0; end; local retVal = 0; local n, n1, label, instr, dst, src; |
︙ | ︙ | |||
42 43 44 45 46 47 48 | return retVal, label, instr, dst, src; end function ProcessLine( l ) local asm_instr; local n,f1,f2,f3,f4 = Fields(l); | > > | | | | | > | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | return retVal, label, instr, dst, src; end function ProcessLine( l ) local asm_instr; local n,f1,f2,f3,f4 = Fields(l); if( l:sub(-1) == '\r' ) then l = l:sub(1,l:len()-1); end; -- chomp line. if( n == 0 ) then print(l); return; end asm_instr = Directive[ string.lower(f2 or f3) ]; if( asm_instr ) then print( asm_instr() ); return; end asm_instr = CPU_instr[ string.upper(f2 or f3) ]; -- if( asm_instr ) then asm_instr = asm_instr[2]; print( asm_instr[2](f2,f3,f4) ); end if( asm_instr ) then local b1, b2, b3 = asm_instr[2](f2,f3,f4); if( b1 ) then b1 = string.format("%02x",b1); end b1 = b1 or " "; if( b2 ) then b2 = string.format("%02x",b2); end b2 = b2 or " "; if( b3 ) then b3 = string.format("%02x",b3); end b3 = b3 or " "; io.write( string.format( "%s %s %s : ", b1, b2, b3 ) ); else io.write( (" "):rep(9) .. ": " ); end -- io.write( string.format("%d=%s - %s - %s - %s\n",n,f1,f2,f3,f4) ); print( l ); end -- Main line -- if( not arg[1] ) then |
︙ | ︙ |
Changes to opcodes.lua.
︙ | ︙ | |||
170 171 172 173 174 175 176 | function do_INV(f1, f2, f3) local retVal = { [0]=0x30, 0x35, 0x3a, 0x3f }; return( retVal[ isReg(f2) ] ); end function do_JMP(f1, f2, f3) | | > > > > > | > > > > > | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | function do_INV(f1, f2, f3) local retVal = { [0]=0x30, 0x35, 0x3a, 0x3f }; return( retVal[ isReg(f2) ] ); end function do_JMP(f1, f2, f3) if( f2:sub(1,1) == '(' ) then -- TODO check for (r0) return 0xf2 ; else return 0xf3,0x00,0x00 ; end end function do_JSR(f1, f2, f3) if( f2:sub(1,1) == '(' ) then -- TODO check for (r0) return 0xce ; else return 0xcf,0x00,0x00 ; end end function do_LD_B(f1, f2, f3) print( f1, f2, f3 ); end function do_LD_W(f1, f2, f3) |
︙ | ︙ | |||
202 203 204 205 206 207 208 209 210 211 212 213 214 215 | end function do_LSR_WT(f1, f2, f3) print( f1, f2, f3 ); end function do_MOVE(f1, f2, f3) local n1 = isReg(f2); local n2 = isReg(f3); if( n1 == n2 ) then error("Cannot move register to itself"); end return( 0x00 + n2*4 + n1 ); end | > > > > > > > > > > > > | 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | end function do_LSR_WT(f1, f2, f3) print( f1, f2, f3 ); end function do_MOVE(f1, f2, f3) if( f2:lower() == "sp" ) then if( isReg(f3) == 0 ) then return 0xf1; else error("SP only can be written from R0"); end end if( f3:lower() == "sp" ) then if( isReg(f2) == 0 ) then return 0xf0; else error("SP only can move into R0"); end end local n1 = isReg(f2); local n2 = isReg(f3); if( n1 == n2 ) then error("Cannot move register to itself"); end return( 0x00 + n2*4 + n1 ); end |
︙ | ︙ |