WWW.DUMAIS.IO
ARTICLES
OVERLAY NETWORKS WITH MY SDN CONTROLLERSIMPLE LEARNING SWITCH WITH OPENFLOWINSTALLING KUBERNETES MANUALLYWRITING A HYPERVISOR WITH INTEL VT-X CREATING YOUR OWN LINUX CONTAINERSVIRTIO DRIVER IMPLEMENTATIONNETWORKING IN MY OSESP8266 BASED IRRIGATION CONTROLLERLED STRIP CONTROLLER USING ESP8266.OPENVSWITCH ON SLACKWARESHA256 ASSEMBLY IMPLEMENTATIONPROCESS CONTEXT ID AND THE TLBTHREAD MANAGEMENT IN MY HOBBY OSENABLING MULTI-PROCESSORS IN MY HOBBY OSNEW HOME AUTOMATION SYSTEMINSTALLING AND USING DOCKER ON SLACKWARESYSTEM ON A CHIP EMULATORUSING JSSIP AND ASTERISK TO MAKE A WEBPHONEC++ WEBSOCKET SERVERSIP ATTACK BANNINGBLOCK CACHING AND WRITEBACKBEAGLEBONE BLACK BARE METAL DEVELOPEMENTARM BARE METAL DEVELOPMENTUSING EPOLLMEMORY PAGINGIMPLEMENTING HTTP DIGEST AUTHENTICATIONSTACK FRAME AND THE RED ZONE (X86_64)AVX/SSE AND CONTEXT SWITCHINGHOW TO ANSWER A QUESTION THE SMART WAY.REALTEK 8139 NETWORK CARD DRIVERREST INTERFACE ENGINECISCO 1760 AS AN FXS GATEWAYHOME AUTOMATION SYSTEMEZFLORA IRRIGATION SYSTEMSUMP PUMP MONITORINGBUILDING A HOSTED MAILSERVER SERVICEI AM NOW HOSTING MY OWN DNS AND MAIL SERVERS ON AMAZON EC2DEPLOYING A LAYER3 SWITCH ON MY NETWORKACD SERVER WITH RESIPROCATEC++ JSON LIBRARYIMPLEMENTING YOUR OWN MUTEX WITH CMPXCHGWAKEUPCALL SERVER USING RESIPROCATEFFT ON AMD64CLONING A HARD DRIVECONFIGURING AND USING KVM-QEMUUSING COUCHDBINSTALLING COUCHDB ON SLACKWARENGW100 MY OS AND EDXS/LSENGW100 - MY OSASTERISK FILTER APPLICATIONCISCO ROUTER CONFIGURATIONAASTRA 411 XML APPLICATIONSPA941 PHONEBOOKSPEEDTOUCH 780 DOCUMENTATIONAASTRA CONTACT LIST XML APPLICATIONAVR32 OS FOR NGW100ASTERISK SOUND INJECTION APPLICATIONNGW100 - DIFFERENT PROBLEMS AND SOLUTIONSAASTRA PRIME RATE XML APPLICATIONSPEEDTOUCH 780 CONFIGURATIONUSING COUCHDB WITH PHPAVR32 ASSEMBLY TIPAP7000 AND NGW100 ARCHITECTUREAASTRA WEATHER XML APPLICATIONNGW100 - GETTING STARTEDAASTRA ALI XML APPLICATION

AVR32 ASSEMBLY TIP

2012-02-25

Cool instructions

on this page, I will describe some instructions I found interesting on the AVR32 CPUs.

BFTEXU and SUBHS

Those two instructions are powerfull. BFTEXU allows you to extract 'n' bits starting at position 'm' in register 'X' and store the result in register 'Y' at position 0 and pad the rest with zeros. Basically, it does all that for you in 1 cycle only:

bfextu r5,r8,5,4 is the same as: mov r5,r8 lsr r5,5 mov r8,0x0F and.w r5,r8

SUBHS r,i will substract 'i' from 'r' and store the result in 'r' only if the carry flag is cleared. Otherwise, it will behave as a NOP. Knowing this, it would be easy to write a function that converts a 32bit number into its ascii representation. Assume that the follwing function takes 'r8' as the input number and we will output each char on the serial port from the MSB to LSB

swap.b r8 mov r4,4 ; we will do 4 iterations, one for each byte 1: bfextu r5,r8,4,4 ; get me the high nibble sub r5,-48 ; substracting -48 is the same as adding 48 right? cp r5,58 ; is the ascii char over '9'? subhs r5,-7 ; if ascii overflowed '9', then add 7 to make it a letter rcall sendSerial bfextu r5,r8,0,4 ; get me the low nibble sub r5,-48 ; substracting -48 is the same as adding 48 right? cp r5,58 ; is the ascii char over '9'? subhs r5,-7 ; if ascii overflowed '9', then add 7 to make it a letter rcall sendSerial lsr r8,8 sub r4,1 brne 1b

BREV

When writing an FFT on a x86 architecture, you dream of having access to such an instruction. BREV allows you to transform 00000000000000000000000000100110 into 01100100000000000000000000000000. It is a bit reversal. I just did that in one cycle only with one instruction. Can you imagine doing that in C? looping through each bit, making shifts, 'OR' etc...

BLD

BLD r,n lets you take bit 'n' from register 'r' and store it in the carry flag. Having this in the carry flag lets you make a conditional branch the way you like without even having to compare anything. Without that instruction, you would need to 'AND' the register with a bit mask, compare the result with 0 and branch conditionally. With BLD, I don't even have to change any registers and I save "AND" step.