{"id":41203,"date":"2004-01-05T07:00:00","date_gmt":"2004-01-05T15:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/01\/05\/why-does-the-x86-have-so-few-registers\/"},"modified":"2004-01-05T07:00:00","modified_gmt":"2004-01-05T15:00:00","slug":"why-does-the-x86-have-so-few-registers","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040105-00\/?p=41203","title":{"rendered":"Why does the x86 have so few registers?"},"content":{"rendered":"<p><a HREF=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/#comment-119403\">One\nof the comments to my discussion of 16-bit calling conventions\nwondered why the 8086 had so few registers<\/a>.<\/p>\n<p>\nThe 8086 was a 16-bit version of the even older 8080 processor,\nwhich had six 8-bit registers, named\nA, B, C, D, E, H, and L.\nThe registers could be used in pairs to products three\n16-bit pseudo-registers, BC, DE, and HL.\nWhat&#8217;s more, you could put a 16-bit address into the HL register\nand use the pseudo-register &#8220;M&#8221; to deference it.\nSo, for example, you could write &#8220;MOV B, M&#8221; and this meant to\nload the 8-bit value pointed to by the HL register pair into the B register.\n<\/p>\n<p>\nThe 8086 took these 8080 registers and mapped them sort of like this:<\/p>\n<ul>\n<li>A -&gt; AL\n<li>H -&gt; BH, L -&gt; BL; HL -&gt; BX; M -&gt; [BX]\n<li>B -&gt; CH, C -&gt; CL; BC -&gt; CX\n<li>D -&gt; DH, E -&gt; DL; DE -&gt; DX\n<\/ul>\n<p>\nThis is why the 8086 instruction set can only dereference\nthrough the [BX] register and not the [CX] or [DX] registers:\nOn the original 8080, you could not dereference through [BC] or [DE],\nonly thorugh M=[HL].\n<\/p>\n<p>\nThis much so far is pretty official. The instruction set\nfor the 8086 was chosen to be upwardly-compatible with the 8080,\nso as to facilitate machine translation of existing 8-bit code\nto this new 16-bit processor.\n<a HREF=\"http:\/\/www.patersontech.com\/Dos\/Byte\/InsideDos.htm\">\nEven the MS-DOS function calls were designed so as to\nfaciliate machine translation<\/a>.\n<\/p>\n<p>\nWhat about the SI and DI registers?  I suspect they were\ninspired by the IX and IY registers available on the Z-80,\na competitor to the 8080 which took the 8080 instruction set\nand extended it with more registers. The Z-80 allowed\nyou to dereference through [IX] and [IY], so the 8086 lets\nyou dereference through [SI] and [DI].\n<\/p>\n<p>\nAnd what about the BP register?  I suspect that was invented\non the fly in order to facilitate stack-based parameter\npassing. Notice that the BP register is the only 8086 register\nthat defaults to the SS segment register and which can be used\nto access memory directly.\n<\/p>\n<p>\nWhy not add even more registers, like today&#8217;s processors with\ntheir palette of 16 or even 128 registers? Why limit the 8086\nto only eight registers (AX, BX, CX, DX, SI, DI, BP, SP)?  Well, that was then\nand this is now. At that time, processors did not have lots of\nregisters. The 68000 had a whopping sixteen registers, but if\nyou look more closely, only half of them were general purpose\narithmetic registers; the other half were used only for\naccessing memory.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A walk back through history.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-41203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>A walk back through history.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/41203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=41203"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/41203\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=41203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=41203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=41203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}