Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

###Unsafe bounds check###

Unsafe bounds check

This kind of bounds check:

if( address+3 >= MEM_SIZE ) {

doesn't work if address is 0xffffffff. It would be better to rewrite that check as this:

if( address >= MEM_SIZE-3 ) {

Better yet, I would change it to this:

if( address > MEM_SIZE-4 ) {

so that the 4 matches the number of bytes you are accessing.

###Pointer support###

Pointer support

Currently, the only instructions you have to load/store from an address are like loadl and storel, which specify their address as part of the instruction. In order to support pointers, I think you will need to add new instructions such as loadindl and storeindl (where "ind" means "indirect").

loadindl would pop a 4 byte address from the stack and use that address to load 4 bytes from memory onto the stack. storeindl would pop a 4 byte address from the stack, then pop a 4 byte value from the stack, then store that value to that address.

So the way you would load from a pointer would be something like:

loadl <ptr address>
loadindl

The way you wuold store to a pointer would be something like:

pushl <value to store>
loadl <ptr address>
storeindl

###Unsafe bounds check###

This kind of bounds check:

if( address+3 >= MEM_SIZE ) {

doesn't work if address is 0xffffffff. It would be better to rewrite that check as this:

if( address >= MEM_SIZE-3 ) {

Better yet, I would change it to this:

if( address > MEM_SIZE-4 ) {

so that the 4 matches the number of bytes you are accessing.

###Pointer support###

Currently, the only instructions you have to load/store from an address are like loadl and storel, which specify their address as part of the instruction. In order to support pointers, I think you will need to add new instructions such as loadindl and storeindl (where "ind" means "indirect").

loadindl would pop a 4 byte address from the stack and use that address to load 4 bytes from memory onto the stack. storeindl would pop a 4 byte address from the stack, then pop a 4 byte value from the stack, then store that value to that address.

So the way you would load from a pointer would be something like:

loadl <ptr address>
loadindl

The way you wuold store to a pointer would be something like:

pushl <value to store>
loadl <ptr address>
storeindl

Unsafe bounds check

This kind of bounds check:

if( address+3 >= MEM_SIZE ) {

doesn't work if address is 0xffffffff. It would be better to rewrite that check as this:

if( address >= MEM_SIZE-3 ) {

Better yet, I would change it to this:

if( address > MEM_SIZE-4 ) {

so that the 4 matches the number of bytes you are accessing.

Pointer support

Currently, the only instructions you have to load/store from an address are like loadl and storel, which specify their address as part of the instruction. In order to support pointers, I think you will need to add new instructions such as loadindl and storeindl (where "ind" means "indirect").

loadindl would pop a 4 byte address from the stack and use that address to load 4 bytes from memory onto the stack. storeindl would pop a 4 byte address from the stack, then pop a 4 byte value from the stack, then store that value to that address.

So the way you would load from a pointer would be something like:

loadl <ptr address>
loadindl

The way you wuold store to a pointer would be something like:

pushl <value to store>
loadl <ptr address>
storeindl
added 587 characters in body
Source Link
JS1
  • 28.8k
  • 3
  • 41
  • 83

###Unsafe bounds check###

This kind of bounds check:

if( address+3 >= MEM_SIZE ) {

doesn't work if address is 0xffffffff. It would be better to rewrite that check as this:

if( address >= MEM_SIZE-3 ) {

Better yet, I would change it to this:

if( address > MEM_SIZE-4 ) {

so that the 4 matches the number of bytes you are accessing.

###Pointer support###

Currently, the only instructions you have to load/store from an address are like loadl and storel, which specify their address as part of the instruction. In order to support pointers, I think you will need to add new instructions such as loadindl and storeindl (where "ind" means "indirect").

loadindl would pop a 4 byte address from the stack and use that address to load 4 bytes from memory onto the stack. storeindl would pop a 4 byte address from the stack, then pop a 4 byte value from the stack, then store that value to that address.

So the way you would load from a pointer would be something like:

loadl <ptr address>
loadindl

The way you wuold store to a pointer would be something like:

pushl <value to store>
loadl <ptr address>
storeindl

###Unsafe bounds check###

This kind of bounds check:

if( address+3 >= MEM_SIZE ) {

doesn't work if address is 0xffffffff. It would be better to rewrite that check as this:

if( address >= MEM_SIZE-3 ) {

Better yet, I would change it to this:

if( address > MEM_SIZE-4 ) {

so that the 4 matches the number of bytes you are accessing.

###Unsafe bounds check###

This kind of bounds check:

if( address+3 >= MEM_SIZE ) {

doesn't work if address is 0xffffffff. It would be better to rewrite that check as this:

if( address >= MEM_SIZE-3 ) {

Better yet, I would change it to this:

if( address > MEM_SIZE-4 ) {

so that the 4 matches the number of bytes you are accessing.

###Pointer support###

Currently, the only instructions you have to load/store from an address are like loadl and storel, which specify their address as part of the instruction. In order to support pointers, I think you will need to add new instructions such as loadindl and storeindl (where "ind" means "indirect").

loadindl would pop a 4 byte address from the stack and use that address to load 4 bytes from memory onto the stack. storeindl would pop a 4 byte address from the stack, then pop a 4 byte value from the stack, then store that value to that address.

So the way you would load from a pointer would be something like:

loadl <ptr address>
loadindl

The way you wuold store to a pointer would be something like:

pushl <value to store>
loadl <ptr address>
storeindl
Source Link
JS1
  • 28.8k
  • 3
  • 41
  • 83

###Unsafe bounds check###

This kind of bounds check:

if( address+3 >= MEM_SIZE ) {

doesn't work if address is 0xffffffff. It would be better to rewrite that check as this:

if( address >= MEM_SIZE-3 ) {

Better yet, I would change it to this:

if( address > MEM_SIZE-4 ) {

so that the 4 matches the number of bytes you are accessing.

lang-c

AltStyle によって変換されたページ (->オリジナル) /