Is there any way to add an 8-bit value to a 32-bit register in x86?
For example, if you do “ADD EAX,8” then the 8 will be encoded as a 32 bit value so you will have “08000000” in your binary. If you are adding by one you can use the INC instruction obviously, but is there any way to ADD a generic 8-bit value in x86 assembly?
Note I don’t think you can do “ADD AL,8” because if AL already has, say, xFE in it then it will not do the carry. What about “ADC AL,8”, though, will that carry the value to AH?
There is an encoding that uses 8 bit sign-extended immediate, it’s listed as
ADD r/m32, imm8opcode83 /0. How you indicate you want that encoding depends on your assembler, but you have forgotten to mention which one you use.nasmfor example automatically uses this encoding if you turn optimization on or if you explicitly ask for it like so:add eax, byte 8. GNU assembler seems to use the shorter encoding too, in fact I don’t know how to force it to 32 bit (kind of the reverse of your problem).