flat assembler
Message board for the users of flat assembler.
Index
> Main > General Assembly Control Flow Tips |
Author |
|
revolution 02 Mar 2018, 11:46
Code: cmp one_thing,another_thing jz .test1_equal ;test1 not equal path ;... jmp .test1_done .test1_equal: ;test1 equal path ;... .test1_done: |
|||
02 Mar 2018, 11:46 |
|
DimonSoft 02 Mar 2018, 13:14
moveax41h wrote: Hello, There’s a general principle called structured programming. It is the first thing in programming that is taught in a university but it’s not common to pay much attention to it when discussing assembly programming. The principle makes code clearer in a language-independent manner. You just have to stick with three basic code structures: sequence, selection and iteration. Sequence is what asm gives you by its nature. Selection can be implemented by code snippets like the one revolution shows. Iteration is also easy to implement. Combining three of them lets one make a program of potentially infinite complexity. The basic idea is that your code should consist of such pieces and all the jumps should be made within them (maybe at different levels). Later you start to see in which cases breaking the rules is good: mostly error handling. |
|||
02 Mar 2018, 13:14 |
|
bitRAKE 03 Mar 2018, 00:42
BT and TEST can be used to signal without effecting the source. Instead of AND/CMP/JZ, use TEST/JNZ or BT/JC. These instruction can also be used on memory directly - allowing you to load into registers only what you need there.
Multiway branches and filters are also possible. Personally, I came by my understanding through a study of logic gates for electronics, and reading the code of others. Boolean algebra is similarly related. |
|||
03 Mar 2018, 00:42 |
|
yeohhs 03 Mar 2018, 12:34
moveax41h wrote:
Chapter 5 Procedures and Chapter 6 Conditional Processing in Kip R. Irvine's book "Assembly Language for x86 Processors (7th Edition)" might be useful to you. There is also Chapter 8 Advanced Procedures. |
|||
03 Mar 2018, 12:34 |
|
moveax41h 04 Mar 2018, 00:39
Wow, thanks for all of the useful info everyone. Learned a ton and also got this thing working properly.
bitRAKE, I appreciate the instruction suggestions... This is the best way to learn - to see exactly why/how an instruction can be used in place of others. Just read some about Structured programming as well. Will check out Kip Irvine's book. Fun stuff. |
|||
04 Mar 2018, 00:39 |
|
Furs 04 Mar 2018, 22:17
I suggest you indent your blocks just like in a HLL, makes it much easier to see IMO. Using revolution's example:
Code: cmp one_thing, another_thing jz .test1_equal ; test1 not equal path ; ... jmp .test1_done .test1_equal: ; test1 equal path ; ... .test1_done: blah |
|||
04 Mar 2018, 22:17 |
|
DimonSoft 05 Mar 2018, 16:13
Furs wrote: I suggest you indent your blocks just like in a HLL, makes it much easier to see IMO. Using revolution's example: I’d say it would turn the amazing smart tabs feature of FASM editor into a useless and stupid feature that comes on your way whenever you try to use it. Unlike HLLs, in asm it is quite important to see clearly where the operands are and where the instruction mnemonic is. I guess, that’s why it is traditional to write asm code in several columns (Fortran might be yet another reason). Typical code blocks for selection and iteration are easily recognizable unless the whole program is a single pile of instructions. |
|||
05 Mar 2018, 16:13 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.