flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2 |
Author |
|
rugxulo 05 Nov 2006, 02:27
Save a byte (this is one of those well-known shortcuts):
Code: 83FB00 CMP BX,0 85DB TEST BX,BX |
|||
![]() |
|
Goplat 05 Nov 2006, 05:13
There's a lot more room for saving space than that... I got it down to 29 bytes
Code: org 100h mov ah,9 mov dx,b p0: int 21h mov bx,b+8 p1: dec bx xor [bx],bh jp p1 jnp p0 db 0c2h b db 8 dup 48,13,10,36 How it works:
|
|||
![]() |
|
2 05 Nov 2006, 10:38
Quote:
Yep,I know that doesn't work all the time,but I think whoever made ASCII intended to make it that way for a reason. It sure makes it easier. I know all about the XOR swap. Even if it weren't the way it is now,with binary,we only have 0 and 1. This means as long as we can swap between them,it works. |
|||
![]() |
|
2 05 Nov 2006, 10:45
Hey guys,I'm a little lost. I don't know anything about those parity jumps
or the test instruction. I am gonna look that up. I also don't quite get how you terminated the program. I definitely like that. You guys really must know how I like small stuff! |
|||
![]() |
|
revolution 05 Nov 2006, 11:53
2 wrote: I like to use bitwise operations when possible. I read that I don't know where/when this myth started but I might be able to guess it goes back to the days when people were doing hardware adders with discrete transistors. Once the whole thing got into silicon and became a CPU then the add/sub/and/or/xor timing difference was no longer true. That must be about 30 years ago now. Amazing how some out of date information can still be floating around to catch people off guard. Hope this helps. |
|||
![]() |
|
rugxulo 05 Nov 2006, 21:26
TEST is the same as AND, but it discards the result (just like CMP is to SUB). ANDing something against itself will only be zero (ZF) if the number is zero. Or something like that.
![]() P.S. You could also OR something against itself to test for zero. |
|||
![]() |
|
LocoDelAssembly 05 Nov 2006, 23:01
You can but is it advisable? suppose these codes
Code: test eax, eax add eax, edx jz .exit Code: or eax, eax add eax, edx jz .exit Both codes executes at same speed on a PPro class (or newer) CPU? |
|||
![]() |
|
2 06 Nov 2006, 03:41
Quote:
OK,so if I understand correctly,the TEST instruction acts as though it were a single bit data type? It uses the ones bit or two operands. The ZF zero flag has the result? I hope I get it. Tell me if I'm wrong. |
|||
![]() |
|
revolution 06 Nov 2006, 10:53
OR eax,eax
AND eax,eax TEST eax,eax They will all produce the same results and alter the EFLAGS register only. CF=OF=0, ZF=set according to register, PF=set according to register, SF=set according to register Although there is a minor speed benefit by using TEST. But the difference is so minor that unless you are writing a hyper-optimised alogrithm it won't be worth the worry. The reason is because with TEST the destination register does not get written back, this can help free up writeback resources and allow surrounding instructions to complete faster. |
|||
![]() |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.