<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Setting a port bit in ASM</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/16542/setting-a-port-bit-in-asm</link><description> I&amp;#39;ve tried a variety of methods for storing a bit address in ASM so I can subsequently SET/CLR that bit but have had no luck. Here&amp;#39;s the pseudo-code for what I want to do: 
 
 1 - Initialize an 8-bit variable (Addr) 
 in my ASM module with the bit 
</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Setting a port bit in ASM</title><link>https://community.arm.com/thread/122099?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2003 21:13:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a3933ec7-643c-4476-bee9-a9ed7bb92edc</guid><dc:creator>Chip Burns</dc:creator><description>&lt;p&gt;Oleg,&lt;br /&gt;
&lt;br /&gt;
I received it, thank you.  I had in fact only checked to see if my idea would compile, had not actually checked to see if it really worked...  : (&lt;br /&gt;
&lt;br /&gt;
Best regards,&lt;br /&gt;
&lt;br /&gt;
Chip Burns&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting a port bit in ASM</title><link>https://community.arm.com/thread/110471?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2003 12:40:52 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:680ba87c-0b60-44e9-ae31-feed42625d20</guid><dc:creator>Oleg Sergeev</dc:creator><description>&lt;p&gt;hi, do you not read my above answer? (=&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting a port bit in ASM</title><link>https://community.arm.com/thread/95711?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2003 11:30:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:229cf237-fd9d-4ebf-ad61-ca077dc68936</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;&lt;i&gt;Also if I pass in an offset to a base address it works fine:&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
MOV ACC,R5&lt;br /&gt;
SETB 0x90+ACC&lt;br /&gt;
&lt;br /&gt;
Does this code &lt;i&gt;work&lt;/i&gt; correctly, or does it just &lt;i&gt;assemble&lt;/i&gt; correctly?&lt;br /&gt;
&lt;br /&gt;
The way I read my instruction set manual, there are only two SETB opcodes.  One sets the carry flag.  The other is a two-byte instruction that takes a bit address.  There is no mode for this instruction that allows an accumulator offset to a base address.&lt;br /&gt;
&lt;br /&gt;
I suspect this code will in fact set bit 70H (90H + ACC == 90H + E0H == 170H, which wraps mod 256 to 70H) regardless of the value of R5 when it is executed.  The simulator shows the results of assembling the code to be D2 70, which is SETB 2E.0 (in the bit-addressable memory), as expected.  I could have hoped for an &amp;quot;out of range&amp;quot; warning on the arithmetic.&lt;br /&gt;
&lt;br /&gt;
If you really want to make that one instruction indirect, you&amp;#39;d have to write self-modifying code to modify the direct bit address in the second byte of the instruction.  There&amp;#39;s lots of reasons why this usually isn&amp;#39;t a good idea.&lt;br /&gt;
&lt;br /&gt;
If you&amp;#39;re passing the address of the bit to a function, then there&amp;#39;s already enough overhead that the AND/OR method shouldn&amp;#39;t add too much more.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting a port bit in ASM</title><link>https://community.arm.com/thread/71777?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2003 04:00:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b21e6147-34c1-4e73-85d7-a303d659240b</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;Keil assembler does not help you here; there is no indirect-via-address bit access commands&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Just to clarify: the 8051 processor itself has no indirect-via-address bit access instruction; therefore &lt;i&gt;&lt;b&gt;no&lt;/b&gt;&lt;/i&gt; assembler can help you here!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting a port bit in ASM</title><link>https://community.arm.com/thread/40781?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2003 02:37:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1ce4cdaa-902b-42f1-8c5a-1e6551752abc</guid><dc:creator>Oleg Sergeev</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;
First of all, you should probably read somemore about assemly language. Keil assembler does not help you here; there is no indirect-via-address bit access commands --- there is only command SETB bit, where bit is direct &lt;b&gt;the number&lt;/b&gt; of a bit in interanl bitfiled or SFR. So you have no ability to set/clr bits with way you indicated. Anyway, you may create a subroutine which does it for you by ANL/ORL commands, something like:&lt;br /&gt;
&lt;pre&gt;
; A - number of bit (0x00...0x7F) to be set in bitfield area (0x20...0x2F)
SUB_SET_BIT:
	JB	ACC.7,SUB_SET_BIT_END	; error number...
	MOV 	B,#8
	DIV	AB			; result: addr/bitnum
	ADD	A,#0x20
	MOV	R0,A			; addr for indirect access
	INC	B
	CLR	A
	SETB	C
SUB_SET_BIT_0:
	RLC	A			; get bit mask
	DJNZ	B,SUB_SET_BIT_0
	ORL	A,@R0			; set bit
	MOV	@R0,A
SUB_SET_BIT_END:
	RET
&lt;/pre&gt;
Unfortunately, it is not possible to access SFRs via indirect mode so if you need for such subroutine for SFRs then you should write 16 ones for each bit-accessible SFR and select them by address table (JMP @A+DPTR, for example).&lt;br /&gt;
Read Keil ASM docs as well.&lt;br /&gt;
&lt;br /&gt;
As about last example, MOV ACC,R5 and SETB 0x90+ACC it does completely different result: it will set bit 0x2E.0 because&lt;br /&gt;
mod256(0x90+0xE0) = bit number 0x70 that&amp;#39;s 0x2E.0 bit.&lt;br /&gt;
Good days!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>