Normally you would use the special set and clear registers with a mask to not disturb the other port pins. Note, this code resets all bits on port1 to zero regardless of the internal function. The effect is that you will see the LED light up at half brightness. The result of this little program is that LED1 is switched on and off as fast as possible resulting in multi MHZ blinking speed. Speed_check() // execute assembler routine include emu8086. The result will be over 255 on third loop (100+100+100), so loop will exit. LDR R3,=0x00040000 set LED 1 on (bit 18 aka P1.18 is 'one') Loop until result fits into AL alone, or 5 times. LDR R1,=0x2009c020 pointer to base of port1 setup a pointer to the base address of port 1 An infinite loop is one that has no exit.
Export my asm function location so that C compiler can find it and link Loop structures: The basic looping structures are DO iterative, do WHILE, and do UNTIL.
HOW TO STOP A LOOP IN EMU8086 HOW TO
Here is some example on how to write a value directly to the port pins: If you want to learn more about the inner stuff of the mbed's CPU get a copy of the UM10360 LPC17xx manual and also take a peek at: It takes a lot of tweaking to get assembler routines right and for the rest of the code I used standard C and mbed libraries. If you do not need the absolute maximum speed I would stick to C, in one of my own projects I deliberately used some assembler to get the 'promised' 120 nsec response to an interrupt and to keep my interrupt routine under 1 usec in total. Note all port registers are in principle 32 bits but you can address them 8, 16 and 32 bits at a time creating very flexible ways of driving the port pins (and very fast too if needed) It will take some studying, not only to understand the IO system but also how all addressing modes of the ARM CPU work.
You can write some binary value directly to the output register. You can create a mask for the selected pin and use the 'set' and 'reset' registers There are several ways to write to port pins from assembler: