flat assembler
Message board for the users of flat assembler.
Index
> Main > Help with hand assembly |
Author |
|
revolution 20 Aug 2024, 23:30
Code: ~ printf 'use32 \n sub byte[0x12345678],4' > test.asm ; fasm test.asm test.bin ; hd test.bin flat assembler version 1.73.31 (16384 kilobytes memory) 1 passes, 7 bytes. 00000000 80 2d 78 56 34 12 04 |.-xV4..| 00000007 ~ printf 'use32 \n mov dword[0x12345678],4' > test.asm ; fasm test.asm test.bin ; hd test.bin flat assembler version 1.73.31 (16384 kilobytes memory) 1 passes, 10 bytes. 00000000 c7 05 78 56 34 12 04 00 00 00 |..xV4.....| 0000000a ~ |
|||
20 Aug 2024, 23:30 |
|
AsmGuru62 20 Aug 2024, 23:37
FASM is made to generate opcodes for you:
Code: Stk dd 0 00405006 |. 832D AC244000 04 SUB DWORD PTR DS:[4024AC], 4 0040500D |. C705 AC244000 78921277 MOV DWORD PTR DS:[4024AC], 77129278 I am not sure why to do it by hand. If this is code to emulate a stack, you are missing one more instruction: Code: 00405006 |. 832D AC244000 04 SUB DWORD PTR DS:[4024AC], 4 0040500D |. 8B0D AC244000 MOV ECX, DWORD PTR DS:[4024AC] 00405013 |. C701 78921277 MOV DWORD PTR DS:[ECX], 77129278 |
|||
20 Aug 2024, 23:37 |
|
AsmGuru62 21 Aug 2024, 01:38
I see.
You maybe trying to generate the actual CPU code for compiled source. Then you still do not need to generate by hand. Just use FASM and debugger. |
|||
21 Aug 2024, 01:38 |
|
Stancliff 21 Aug 2024, 02:44
IF fasm can do it I am all for trying to do so. It will make this topic very short. I still can't use a debugger though. How did you tell fasm to do that? Just a normal assemble and then use debugger to read it back?
Thanks for the help The code was to put a number onto the stack. It's usage is to be embedded into a compiled word so that it runs during runtime for that compiled word. This is very common in forth. Since the source for the second command is an immediate and not considered directly from memory it shouldn't need the extra step through the register. If it was impossible fasm would have complained. |
|||
21 Aug 2024, 02:44 |
|
bitRAKE 21 Aug 2024, 08:52
The tool presented in this video and this thread allows viewing the resulting bytes as you edit code - "real-time assembler".
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
21 Aug 2024, 08:52 |
|
AsmGuru62 21 Aug 2024, 17:29
"Just a normal assemble and then use debugger to read it back?"
Yes. So, you are not use a debugger because the font is too small? I think someone posted the way to increase the font. In any event, let us see what is happening with the two lines of code you posted: Code: sub [Stk],4 mov [Stk],0x11223344 I am assuming the 'Stk' is a pointer to the top of the stack and it is defined as 'DD'. Line #1 says: "subtract 4 from the contents of the label 'Stk'" Line #2 says: "store 0x11223344 into the contents of the label 'Stk'" Basically, you are replacing (damaging) the stack top pointer with a value of 0x11223344. What you need is to store 0x11223344 into where stack top pointer points to (after SUB). That is why you need to load the 'Stk' into a register and write 0x11223344 into that address. Code: +--------------+-- [Stk]-4 after SUB | 0x11223344 | +--------------+-- [Stk] before SUB | | | | | | | | | | +--------------+ |
|||
21 Aug 2024, 17:29 |
|
Stancliff 22 Aug 2024, 02:53
registers behave differently than variables during indirection... not the first time I have been caught like that. This is a big incentive to keep the data stack in a register instead of a variable. I have to double check some code here and there since I doubt I implemented the variable based stack pointer correctly.
|
|||
22 Aug 2024, 02:53 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.