flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Tyler 01 Feb 2011, 22:41
1:
The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of two (specifically, from 2N for an N-bit two's complement) I don't really understand it the way they explain it. I see it as the negative is denoted by extending 1s instead of the implied 0s. Like, 2=00000010 (notice the 6 implied 0s), 8bit -2 = 11111110 (notice that those 0s were replaced with 1s. 2: imul and idiv? |
|||
![]() |
|
revolution 01 Feb 2011, 22:55
One's compliment: not eax
Two's compliment: neg eax |
|||
![]() |
|
b1528932 02 Feb 2011, 00:12
1. so this compliment is way of representing negative and positive data or what.
neg eax is transformation like -6 <=> 6, not eax is -6 <=> 5. and what has to do with compliment, whats compliment, i dont understand that word maybe in that context. There is instruction btc, wich flips a bit and set cf to old value. Is that it? compliment = flip all bits, and in ones compliment you get negative value, while in twos you get negative - 1? 2. And what of data that doesnt fit into register? IMHO x86 ALU sucks, because it should support arithmetics on non-fixed length data. It should implement hardware operations as it do now, but simply over not fixed ammount of bytes. For example, it should take pointer to memory wich would contain pointer to data and their length. And even it could allow for more complex operations than basic 2. Whatever, why not additional chip designed just to do math, and not implement anything arithmetic on x86. We could go 1 step ahead, and strip x86 from logical functions as well. 1 chip pure io, 1 logic, 1 arithmetic. |
|||
![]() |
|
revolution 02 Feb 2011, 00:23
b1528932 wrote: compliment? b1528932 wrote: Whatever, why not additional chip designed just to do math, and not implement anything arithmetic on x86. We could go 1 step ahead, and strip x86 from logical functions as well. 1 chip pure io, 1 logic, 1 arithmetic. |
|||
![]() |
|
Tyler 02 Feb 2011, 00:37
1 Yes, positive and negative. Positive in twos complement is just like non-twos-compliment, just you can't use the most significant bit.
2. That's too complex for circuitry. Just do it in software. I realize it's a pain to try to code such things in asm, so use an HLL. |
|||
![]() |
|
edfed 02 Feb 2011, 00:38
neg = not +1
a CPU is a Central Processing Unit, and is designed to compute things. then, X86, as a CPU family, is able to compute things, in one single chip. non need to separate chips to do what can do a single 20mm² chip. |
|||
![]() |
|
b1528932 02 Feb 2011, 00:41
1. thank you now i finally get it. Initialy i though it have something to do with ammount of states 1 bit can have.
2. No its not that hard if i use straightforward method, but why not make cpu do that for me? It would be however impossible in HLL, carry/borrow in C? Good joke. Signed division? Good luck with that. |
|||
![]() |
|
revolution 02 Feb 2011, 00:43
b1528932 wrote: 2. No its not that hard if i use straightforward method, but why not make cpu do that for me? |
|||
![]() |
|
Tyler 02 Feb 2011, 01:22
Actually, 64 bit integers make it pretty easy to carry. Not so efficient, but I don't care. If you want efficiency, use GMP. They have custom asm routines for pretty much everything.
Code: // adds a + b and returns an array of ints, in least to most significant order. void add(uint32_t a, uint32_t b, uint32_t buf) { buf[0] = (uint64_t)a + b & 0xffffffff; // least significant dword buf[1] = ((uint64_t)a + b) >> 32; // put overflow into second int } |
|||
![]() |
|
b1528932 02 Feb 2011, 02:21
Now try 4096 bit mod 512 bit.
|
|||
![]() |
|
Tyler 02 Feb 2011, 03:01
The concept scales. I'm not going to waste my time proving what has already been proven. I only do that in math. Yet again, I'm going to defer to GMP. The have done it, so any statement saying it can't be done is false by default.
|
|||
![]() |
|
b1528932 02 Feb 2011, 03:13
Ok maybe a little correction from me: When i ment 'impossible' i ment 'a huge waste of time, memory, and health'.
|
|||
![]() |
|
idle 02 Feb 2011, 06:05
Quote: and then xor original signs. If xor is 1 neg result, if xor is 0, leave result. In case division also do it to reminder. sign ADD sign does near same: 01 + 01 = 10 = '+' 01 + 00 = 01 = '-' [quote=]...division...[/quote] remember decimal div: 10 / 1, we have 10 subtract cycles max when dividend's and divisor's places differ by 1 100 / 1, 3 places versus 1 give 100 subtract cycles max 100 / 10, 3 places versus 2, give 10 max for binary division difference in 1 place gives 2 sub cycles/iteration max: 10b / 01b 1010b / 111b |
|||
![]() |
|
idle 02 Feb 2011, 06:11
myself wrote:
2^places |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.