Skip to content
Snippets Groups Projects
Commit 69b50a5a authored by Jason Hiser's avatar Jason Hiser :tractor:
Browse files

ZS-86: Dealt with sledding and KS-asm issues

Large ints as constant operands are weird in ks-asm.  Need to use
positive value, in hex, for less than max-signed-int, and negative
hex values for values between max-signed-int and max-unsigned-int.
parent 54060064
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#include <iostream> // std::cout
#include <string> // std::string, std::to_string
#include <fstream>
#include <irdb-util>
namespace zipr
{
......@@ -25,6 +26,27 @@ static int ceildiv(int a, int b)
return (a+b-1)/b;
}
//
// Convert a 32-bit integer into a string that keystone will accept
// without indicating an overflow.
// return a string
inline string to_ks_string(uint32_t val)
{
// Ks is very funky about what integers it accepts.
// 31-bit integers work in hex
if(val <= 0x7fffffff)
{
return "0x"+to_hex_string(val);
}
// and negative 31-bit integers work in hex.
else
{
return "-0x"+to_hex_string(-val);
}
}
#define ALLOF(a) begin(a),end(a)
ZiprPinnerX86_t::ZiprPinnerX86_t(Zipr_SDK::Zipr_t* p_parent) :
......@@ -534,7 +556,7 @@ Instruction_t* ZiprPinnerX86_t::Emit68Sled(RangeAddress_t addr, Sled_t sled, Ins
for(int i=0;i<number_of_pushed_values;i++)
{
string cmp_str="cmp "+decoration+" ["+stack_reg+"+ "+to_string(i*stack_push_size)+"], "+to_string(pushed_values[i]);
string cmp_str="cmp "+decoration+" ["+stack_reg+"+ "+to_string(i*stack_push_size)+"], "+to_ks_string(pushed_values[i]);
Instruction_t* cmp=addNewAssembly(m_firp, nullptr, cmp_str);
Instruction_t *jne=addNewAssembly(m_firp, nullptr, "jne 0");
cmp->setFallthrough(jne);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment