user532051
user532051

Reputation: 21

Assembler in C using functions

HI all, I am trying to design an assembler in C based on some instruction sets. I want to read a assembly language file containing instructions. IN the hex file there is hex data, integer data and negative integer data. I need to convert that data into 8 bit hexadecimal data , out of which 6 bit represents hexadecimal data and the remaining 2 bit will be of opcode. For example ; ldc 0x1000 output: 00100000 (opcode of ldc is 00) ldc -3; output : fffffd00 (6 bit 2s complement of +3).

I am trying ltoa to convert the integer into hexadecimal, but its giving string as output so i am not able to append 0s . PLease suggest urgentl

Upvotes: 1

Views: 285

Answers (1)

Hans Passant
Hans Passant

Reputation: 941970

You seem to confuse bits with nibbles. One hexadecimal digit represents 4 bits. The opcode can store a 24 bit constant, 6 nibbles. Read the value from the string with strtol() and left-shift it by 8. Or with the opcode.

Upvotes: 2

Related Questions