{"id":86,"date":"2012-05-24T08:42:18","date_gmt":"2012-05-24T08:42:18","guid":{"rendered":"http:\/\/www.electronic-products-development.com\/?p=86"},"modified":"2022-02-18T15:37:50","modified_gmt":"2022-02-18T15:37:50","slug":"assembler","status":"publish","type":"post","link":"https:\/\/ibex.tech\/embedded\/microchip\/pic24\/c30-compiler\/assembler","title":{"rendered":"Assembler"},"content":{"rendered":"<h4>\nNotes<br \/>\n<\/h4>\n<h5>\nBit Numbers<br \/>\n<\/h5>\n<p>\nUse # in front of the number, so bit 0 is &quot;#0&quot;\n<\/p>\n<h5>\nSpecial Function Registers<br \/>\n<\/h5>\n<p>\nYou can use SFR&#39;s in&nbsp;the assembler directly instead of&nbsp;including&nbsp;via an&nbsp;input or output. &nbsp;Doing this is faster as the compiler won&#39;t move the SFR via W0 and instead will access it directly.\n<\/p>\n<h5>\nMultiple Assembler Statements<br \/>\n<\/h5>\n<p>\nUse &quot;\/n&quot; to seperate multiple assemlber commands\n<\/p>\n<h4>\nUsing Assembler<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n      asm ( &quot;instruction&quot; );\r\n\r\n\r\n      asm volatile (&quot;mov %0,w0&quot;     \r\n      :                                   \/\/Outputs\r\n      : &quot;g&quot; (pic_address.word.MSW)        \/\/Inputs\r\n      : &quot;w0&quot;);                            \/\/Clobbers\r\n      asm volatile ( &quot;mov w0,TBLPAG&quot; );\r\n\r\n\r\n      asm volatile (&quot;mov %0, w2&quot;\r\n      :                                   \/\/Outputs\r\n      : &quot;g&quot; (data_l)                      \/\/Inputs\r\n      : &quot;w2&quot;);                            \/\/Clobbers\r\n\r\n      asm volatile (&quot;goto %0&quot;\r\n      :                                   \/\/Outputs\r\n      : &quot;g&quot; (FLASH_FIRMWARE_START_ADDRESS)      \/\/Inputs\r\n      );                                  \/\/Clobbers\r\n\r\n<\/code><\/pre>\n<h5>\nWait for IRQ bit to be set while loop in assembler<br \/>\n<\/h5>\n<pre>\r\n<code>\r\n\t\/\/while (!IFS0bits.T2IF)\r\n\t\/\/\t;\r\n\t\/\/LATDbits.LATD0 = 0;\r\n\t\/\/Assembler equivalent:\r\n\t__asm__ volatile (&quot;loop1: btss IFS0,#7 \\n goto loop1 \\n bclr LATD,#0&quot;\r\n\t:\t\t\t\t\t\t\t\/\/Outputs\r\n\t:\t\t\t\t\t\t\t\/\/Inputs\r\n\t: );\t\t\t\t\t\t\/\/Clobbers\r\n<\/code><\/pre>\n<h5>\nMove register to port at specific moment<br \/>\n<\/h5>\n<pre>\r\n<code>\r\n\t__asm__ volatile (&quot;mov %0,W0 \\n setm LATD \\n nop \\n nop \\n nop \\n mov W0,LATD&quot;\r\n\t:\t\t\t\t\t\t\t\/\/Outputs\r\n\t: &quot;g&quot;(data_out)\t\t\t\t\/\/Inputs\r\n\t: &quot;w0&quot;);\t\t\t\t\t\/\/Clobbers\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Notes Bit Numbers Use # in front of the number, so bit 0 is &quot;#0&quot; Special Function Registers You can use SFR&#39;s in&nbsp;the assembler directly instead of&nbsp;including&nbsp;via an&nbsp;input or output. &nbsp;Doing this is faster as the compiler won&#39;t move the SFR via W0 and instead will access it directly. Multiple Assembler Statements Use &quot;\/n&quot; to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-c30-compiler"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":4,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":555,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/86\/revisions\/555"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}