Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look like incorrect result in assembling push numeric value in intel assembler #330

Closed
4144 opened this issue Sep 6, 2021 · 6 comments
Closed

Comments

@4144
Copy link

4144 commented Sep 6, 2021

command from example dir: ./fcml_asm -asa32 -osa32 -m32 "push 80h"

Return this:

Number of the assembled instructions: 2
Instruction: 1
 Code: 6880000000
 Code length: 5
Instruction: 2
 Code: 666a80
 Code length: 3
Best instruction chosen by the assembler: 2

But 666a80 look like wrong.
This is bug? or exists way to give to push information about argument size?

@swojtasiak
Copy link
Owner

This behavior is 100% correct, as 080h is a positive value which cannot be encoded using imm8. So, if you'd like to get 6a80 you'd have to explicitly mark the operand as a negative one:

./fcml_asm -asa32 -osa32 -m32 "push -80h"
Number of the assembled instructions: 2
Instruction: 1
 Code: 6880ffffff
 Code length: 5
Instruction: 2
 Code: 6a80
 Code length: 2
Best instruction chosen by the assembler: 2

@4144
Copy link
Author

4144 commented Jan 20, 2024

this push do 16 bit push on 32 bit system.

how to use push 0x80 for 32 bit push operation? May be push32 or something like this?
i have this issue in assembler. if use normal 32 bit code, this small push corrupting stack

@swojtasiak
Copy link
Owner

So, please correct me if I'm wrong, because I'm not sure if I understand the problem. Would you like to have the first instruction to be marked as the one chosen by the assembler as the preferred one? Something like this:

Number of the assembled instructions: 2
Instruction: 1
 Code: 6880000000
 Code length: 5
Instruction: 2
 Code: 666a80
 Code length: 3
Best instruction chosen by the assembler: 1

@4144
Copy link
Author

4144 commented Jan 20, 2024

All options in assembler or in command line tool set flags to use 32 bit code

if in sample assembler code

...
push var
...

as result some push commands will change esp to value 4, and some push commands if var == 0x80 will change esp to 2 bytes.

i think 32 bit code in push commands must always change esp to 4 bytes?

@swojtasiak
Copy link
Owner

Yes, I think that it makes perfect sense, the instruction generated for the default 32-bit operand size should be the one preferred here. I'll extend the instruction chooser to respect such cases.

@swojtasiak swojtasiak reopened this Jan 20, 2024
swojtasiak added a commit that referenced this issue Jan 23, 2024
#330 Prefer instructions which don't override ASA and OSA over the shortest ones.
@swojtasiak
Copy link
Owner

swojtasiak commented Jan 23, 2024

The fix has been merged with master, 1.3.0 will be released soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants