4 ms·
Anyone have questions on the DAA instruction? This is a bit of a niche post, I have to admit.
by kens 4y ago
Anyone have questions on the DAA instruction? This is a bit of a niche post, I have to admit.
- jamesfinlayson 4y agoIf BCD is the only thing it's applicable for I don't think it has much use - I can't imagine any modern compilers generating BCD instructions nor any hand-rolled assembly making use of it these days. > Even Intel's x86 processors are moving away from the DAA instruction; it generates an invalid opcode exception in x86-64 mode. That's the first I've heard of that so I'm guessing no one complained.
- rvalles 4y agoI have used DAA recently, in my "load option ROM in RAM floppy tool"[0]. Specifically, I use it for printing numbers as hexadecimal[1], as unfortunately the ASCII standard is not arranged in a way as to facilitate this. 0. https://github.com/rvalles/optromloader/ https://github.com/rvalles/optromloader/ 1. https://github.com/rvalles/optromloader/blob/master/optromloader.asm#L182 https://github.com/rvalles/optromloader/blob/master/optromlo...
- gfaure 4y agoI only remember the DAA instruction because it was the last instruction I implemented in my Game Boy emulator. Since it's mainly used for end-user display of game scores, for most games it doesn't lead to any behaviour problems apart from messed up numeric strings, even if not implemented.
- MBCook 4y agoDitto! I fished the CPU emulation on the emulator I’m writing around Christmas and I purposefully pushed DAA to the end of my instruction TODO list. It’s not that bad conceptually but in practice making sure all the flags are set right by the other instructions so DAA would work is a bit of a pain.
- dezgeg 4y agoAnother GB emulator hobbyist here :) My dim recollection is that Pokemon uses BCD for in-game cash, so there you might be able to 'cheat' or either never buy anything if BCD stuff is left unimplemented :)
- anticensor 4y agoCan you make a post on the ASCII adjust series too? I would have expected both in a single blog post, though.
- kens 4y agoThere's not a lot to say about the ASCII adjust instructions. I mention them in footnote 2. They are the same idea except they act on a single BCD digit. They aren't specifically for ASCII, but if you ignore the upper nybble, ASCII digit characters match the BCD values.
- atq2119 4y agoSince reverse engineering the 8086 is your thing, I was really hoping for this blog post to go into how the instruction is actually implemented. Is it all fixed function in the ALU? Is it micro-coded and if so, how?
- userbinator 4y agoGiven that it's a 4-cycle instruction (and a reg-reg add is 3), it seems rather quick to be microcoded. (As an aside, Google gives absolutely horrible results if you search for "8086 DAA instruction timing". At least half the ones on the first page seem to be for the 8085, there's also this article itself and the discussion on HN, neither of which have the information.)
- kens 4y agoThis article is sort of a prelude to looking at the 8086's hardware. (I was looking at the Intel documentation and realized it was confusing and slightly wrong, so needed to figure out what is really happening.) The 8086 implements the instruction in microcode, but like all the arithmetic operations, the interesting stuff happens in the ALU. In particular, the ALU hardware has a DAA instruction that figures out what correction value is needed and adjusts the flags appropriately. Another microcode instruction performs the addition. So the microcode is just four instructions long.