mikeash.com pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html commentshttp://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#commentsmikeash.com Recent CommentsFri, 29 Mar 2024 10:29:09 GMTPyRSS2Gen-1.0.0http://blogs.law.harvard.edu/tech/rssvczilla - 2011-12-31 07:30:43http://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#commentsI'd hate to be an architecture 'nazi' but I couldn't help but notice a mistake concerning memory in the article. <br /> <br />It's stated that all physical addresses are 48 bit wide and that bits 48-63 are all zeroes. <br /> <br />In fact this is only true for linear addresses (which are addresses before paging translation) and only when the processor is a 64 bit processor in compatibility mode. <br /> <br />Physical addresses are 52 bits (and this is implementation dependent). <br /> <br />When the processor is in 64-bit mode all linear addresses must be in what is called a canonical form. <br /> <br />Imagine a 48-bit logic address as signed int which is sign extended to 64 bit when stored. <br /> <br />Or said otherwise for that address bits 48 to 64 are a copy of bit 47. <br /> <br />In general kernel implementations on different operating systems occupy the negative physical address space. <br /> <br />It's a forward looking compatibility feature. <br />That way if in a future implementation they widen physical or linear addresses everything will be at the same relative offset from zero. <br />&nbsp; <br /> <br />22f5b08f5f1355d1abf184ed4f887416Sat, 31 Dec 2011 07:30:43 GMTScott Little - 2011-12-20 13:11:20http://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#commentsGreat stuff! I was thinking that this type of thing would be great to see after Mike's previous article about getting to the Assembly. I do a lot of hacking and swizzling in Mail and am often looking at the assembly of Mail.app and Message.framework, but mostly I don't understand. <br /> <br />Thanks for this primer and I'm looking forward to Part 2!7ee1144bc55b20f50d5c82941be38c53Tue, 20 Dec 2011 13:11:20 GMTHugh Fisher - 2011-12-20 01:35:12http://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#commentsBJ Homer, the register naming conventions on x86 are an evolutionary hangover from the dim, distant days of the 1970s. <br /> <br />Historically mainframe CPUs, like the IBM 360 which is still with us, had 16 or more general purpose registers numbered from 0. Minicomputers like the PDP-11 had fewer but still general purpose registers, also numbered from 0. You can/could see these influences in the PowerPC and Motorola M68K which used similar naming schemes, as did most RISC architectures. <br /> <br />The x86, though, evolved in a pure microprocessor environment. The first 8080 and then 8086 had so few transistors that every register had a unique purpose. You literally could only add numbers in the accumulator (AX) register, you could only use the string index (SI) register to fetch a byte at an offset from an address, and so on. Since there were so few registers and each was different it made sense to give them different names. <br /> <br />The 8 bit 8080 had an 8 bit accumulator while the 8086 was 16 bit. Intel wanted the 8086 to be largely source compatible - and that's assembler source compatible - so made it easy to for 8 bit code to use AL. (Why AH, the top 8 bits of a 16 bit accumulator, exists is a mystery to me but presumably it had some purpose.) <br /> <br />With the 386 the architects finally had enough transistors to switch to general purpose registers where you could (almost) apply any operation to any register, improving both aesthetics and performance, but the hideous names had to stay for backwards compatibility. In the 1980s and even 1990s PC programs were still often written in assembly language. <br /> <br />MMX and SSE, being post 386, got general purpose registers from the start and reg#N names. When AMD extended the x86 architecture to 64 bit addressing they also doubled the number of registers and named them R8 to R15. <br /> <br />Computer architecture textbooks in the 1980s and 1990s didn't use the x86 for examples because it was so kludgy, preferring the cleaner 68K/RISC designs. It says something about elegance vs practicality that the x86 is still with us and those others mostly aren't :-( <br /> <br />cbbfd0859385f6ba64d58ff0976c52dcTue, 20 Dec 2011 01:35:12 GMTGwynne Raskind - 2011-12-17 14:16:29http://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#comments<b>Steve, Alistair:</b>I'm not very familiar with the ARM architecture at the assembly language level, but I guess this is the perfect time to learn! I'll see what I can do about an ARM version once I've finished part 2, since it seems so popular an idea :).a82e3b86cdbea5f21dcd6b47960216c0Sat, 17 Dec 2011 14:16:29 GMTAlistair - 2011-12-17 10:28:10http://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#commentsWhat a superb article, thanks for taking the time to write it. As someone else said, yes please, a version for ARM. That really took me back!641e36f4b9788be2edbca57514f027b1Sat, 17 Dec 2011 10:28:10 GMTJeroen - 2011-12-17 00:47:58http://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#commentsGeesh that brings back the memories! (of the much nicer 68K and PPC though…) <br /> <br />Fire them at the moon so they go splat and remain there as a warning for the future. <br /> <br />Great stuff…1564a8d6a11978e5a034a31b3b310374Sat, 17 Dec 2011 00:47:58 GMTmikeash - 2011-12-16 17:06:20http://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#commentsFire them, out of a cannon, into the sun, perhaps?d52a2890e4889548496ea2bd3be03573Fri, 16 Dec 2011 17:06:20 GMTBJ Homer - 2011-12-16 16:50:00http://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#commentsThis is very useful. I've been meaning to find a good primer on reading assembly for a while, and this couldn't be more appropriate. <br /> <br />But who in the world came up with these register names? Can we fire them?4b00fa1e4c1a3a128ce7b5ff779496aaFri, 16 Dec 2011 16:50:00 GMTSteve Weller - 2011-12-16 15:51:06http://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#commentsPlease repeat for ARM!a1b67f9798f652a6796e771a4ee3c181Fri, 16 Dec 2011 15:51:06 GMTDave - 2011-12-16 15:23:51http://www.mikeash.com/?page=pyblog/friday-qa-2011-12-16-disassembling-the-assembly-part-1.html#commentsMy goodness this is fantastic. <i>*bookmarked*</i>2d4aad29f89a29d61e3adaa02957be44Fri, 16 Dec 2011 15:23:51 GMT