Website Summary Files Commits Branches @commit @diff @stats
path: root / spasm / src / asm / bytecode.cpp
diff options
context:
space:
mode:
Commita7cd9d4f8d83024402bacb39786e5e1a018a0a04 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-14 23:45:56 +0200
Committer
 Martin Dobrev <martindobrev0@gmail.com>
2018-11-14 23:45:56 +0200
Files1f99c6f8d00d9b94b69c8f3525643344a32d7414 /spasm/src/asm/bytecode.cpp
IPL-a7cd9d4f8d83024402bacb39786e5e1a018a0a04.tar
IPL-a7cd9d4f8d83024402bacb39786e5e1a018a0a04.tar.gz
IPL-a7cd9d4f8d83024402bacb39786e5e1a018a0a04.zip
Parent9a7a8a31e75d1b85274ef46ca29714270062809e (diff)
Spasm can assemble programs on with the new instruction set (#47)
* Use checkout as-is, commit as-is * Spasm can assemble programs based on the new instruction set
1 files changed, 36 insertions, 8 deletions
-rw-r--r--spasm/src/asm/bytecode.cpp44
diff --git a/spasm/src/asm/bytecode.cpp b/spasm/src/asm/bytecode.cpp
index 27fed2b..39f1de6 100644
--- a/spasm/src/asm/bytecode.cpp
+++ b/spasm/src/asm/bytecode.cpp
@@ -28,8 +28,15 @@ void Bytecode_File::push_opcode(Bytecode_Stream::Opcode_t opcode)
void Bytecode_File::push_integer(int number)
{
- for (size_t i = 0; i < sizeof(int); ++i)
- push_byte((number >> (i << 3)) & 0xff);
+ if (number <= 0xff)
+ {
+ push_byte((byte)number);
+ }
+ else
+ {
+ for (size_t i = 0; i < sizeof(int); ++i)
+ push_byte((number >> (i << 3)) & 0xff);
+ }
}
void Bytecode_Memory::push_byte(Bytecode_Stream::byte byte)
@@ -44,20 +51,41 @@ void Bytecode_Memory::push_opcode(Bytecode_Stream::Opcode_t opcode)
void Bytecode_Memory::push_integer(int number)
{
- for (size_t i = 0; i < sizeof(int); ++i)
- push_byte((number >> (i << 3)) & 0xff);
+ if (number <= 0xff)
+ {
+ push_byte((byte)number);
+ }
+ else
+ {
+ for (size_t i = 0; i < sizeof(int); ++i)
+ push_byte((number >> (i << 3)) & 0xff);
+ }
}
void Bytecode_Memory::set_location(size_t index, size_t location)
{
- for (size_t i = 0; i < sizeof(size_t); ++i)
- _bytecode.at(index + i) = ((location >> (i << 3)) & 0xff);
+ if (location <= 0xff)
+ {
+ _bytecode[index] = (byte)location;
+ }
+ else
+ {
+ for (size_t i = 0; i < sizeof(size_t); ++i)
+ _bytecode.at(index + i) = ((location >> (i << 3)) & 0xff);
+ }
}
void Bytecode_Memory::push_location(size_t location)
{
- for (size_t i = 0; i < sizeof(size_t); ++i)
- _bytecode.push_back((location >> (i << 3)) & 0xff);
+ if (location <= 0xff)
+ {
+ push_byte((byte)location);
+ }
+ else
+ {
+ for (size_t i = 0; i < sizeof(size_t); ++i)
+ _bytecode.push_back((location >> (i << 3)) & 0xff);
+ }
}
const Bytecode_Memory::Bytecode& Bytecode_Memory::bytecode() const