     10 REM La jaca Paca va para Alava y tu madre no lo dice pero me mira mal y ve el capitan pirata canatando alegre en la popa Asia a un lado al otro Europa.
     20 '
     30 ' machinecode.bas
     40 '
     50 ' Example of use of machine code in Blassic.
     60 ' (C) Julian Albo 2002-2004
     70 ' Use and distribution allowed under the GPL license.
     80 '
     90 ' Don't modify the line 10 !
    100 '
    110 DEF INT a-z
    120 usealloc= NOT 0 ' Use allocation functions / use the rem line.
    130 func= 1 ' Function used
    140 GOSUB 9000
    150 PRINT "Address: "; HEX$ (addr, 8); " hex"
    160 IF func <> 0 THEN GOTO 200
    170 PRINT USR (addr, 1, 10, 100, 1000, 10000, 100000)
    180 GOTO 230
    200 x%= 1
    210 PRINT HEX$ (USR (addr, VARPTR (x%) ) )
    220 PRINT HEX$ (x%)
    230 IF usealloc THEN FREE_MEMORY (addr)
    240 END
    250 REM
   1000 r= PEEK (a) + 256 * (PEEK (a+1) + 256 * (PEEK (a+2) + 256 * PEEK (a+3) ) )
   1010 RETURN
   5000 REM Restore
   5010 ' x86
   5020 IF func = 0 THEN RESTORE 10000 ELSE IF func = 1 THEN RESTORE 15000 ELSE RESTORE 16000
   5030 ' arm
   5040 REM if func = 0 then RESTORE 20000 else if func = 1 then restore 25000 else restore 26000
   5050 ' HP pa-risc
   5060 REM RESTORE 30000
   5070 RETURN
   6000 REM Compute size of machine code
   6010 bytecount= 0
   6020 READ code$
   6030 IF code$ = "xx" THEN RETURN
   6040 bytecount= bytecount + 1
   6050 GOTO 6020
   9000 REM Inicio
   9010 GOSUB 5000
   9020 GOSUB 6000
   9030 GOSUB 5000
   9040 IF usealloc THEN GOTO 9150
   9050 p= PROGRAMPTR
   9060 a= p : GOSUB 1000 : n= r
   9070 IF n <> 10 THEN END
   9080 a= p + 4 : GOSUB 1000 : l= r
   9090 IF l <= 0 THEN END
   9100 REM A byte 0 terminates the listing of the line.
   9110 REM You can see an empty REM in line 10 after execution.
   9120 POKE p + 10, 0
   9130 addr= p + 11
   9140 GOTO 9160
   9150 addr= ALLOC_MEMORY (bytecount)
   9160 p= addr
   9170 READ code$
   9180 REM PRINT code$; "-";
   9190 IF code$ = "xx" THEN RETURN
   9200 code= VAL ("&" + code$)
   9210 REM print hex$ (code, 2); "-";
   9220 POKE p, code
   9230 p= p + 1
   9240 GOTO 9170
  10000 '
  10010 ' Machine code
  10020 ' I compiled this with g++ -O3 -fPIC -S, then assembled with as -a
  10030 ' to obtain the codes (masters of assembler, excuse me).
  10040 ' int test (int nparams, int * param)
  10050 ' {
  10060 '       int r= 0;
  10070 '       for (int i= 0; i < nparams; ++i)
  10080 '               r+= param [i];
  10090 '       return r;
  10100 ' }
  10110 DATA 55             ' pushl %ebp
  10120                     ' .LCFI0:
  10130 DATA 89, E5         ' movl %esp, %ebp
  10140                     ' .LCFI1:
  10150 DATA 8B, 4D, 8     ' movl 8(%ebp), %ecx
  10160 DATA 31, C0         ' xorl %eax, %eax
  10170 DATA 31, D2         ' xorl %edx, %edx
  10180 DATA 39, C8         ' cmpl %ecx, %eax
  10190 DATA 56             ' pushl %esi
  10200                     ' .LCFI2:
  10210 DATA 8B, 75, 0C     ' movl 12(%ebp), %esi
  10220 DATA 7D, 16         ' jge .L8
  10230 DATA 8D, B4, 26, 00 ' .p2align 4,,15
  10240 DATA 00, 00, 00, 8D
  10250 DATA BC, 27, 00, 00
  10260 DATA 00, 00
  10270                     ' .L9:
  10280 DATA 03, 04, 96     ' addl (%esi, %edx, 4), %eax
  10290 DATA 42             ' incl %edx
  10300 DATA 39, CA         ' cmpl %ecx, %edx
  10310 DATA 7C, F8         ' jl .L9
  10320                     ' .L8:
  10330 DATA 5E             ' popl %esi
  10340 DATA 5D             ' popl %ebp
  10350 DATA C3             ' ret
  10360 DATA xx             ' End of code
  15000 '
  15010 ' Func 1
  15020 '
  15030 ' int test (int, int *)
  15040 ' {
  15050 '        return 0x12345678;
  15060 ' }
  15070 'DATA 55             ' pushl %ebp
  15080 'DATA 89, E5         ' movl %esp, %ebp
  15090 DATA B8, 78, 56, 34 ' movl $305419896, %eax
  15100 DATA 12
  15110 'DATA 5D             ' popl %ebp
  15120 DATA C3             ' ret
  15130 DATA xx             ' End of code
  16000 '
  16010 ' Func 2
  16020 '
  16030 ' int test (int, int * param)
  16040 ' {
  16050 '      return 0x9ABCDEF0;
  16060 ' }
  16070 DATA 55             ' pushl %ebp
  16080 DATA 89, E5         ' movl %esp, %ebp
  16090 DATA 8B, 45, 0C     ' movl 12(%ebp), %eax
  16100 DATA 8B, 00         ' movl (%eax), eax
  16110 DATA C7, 00, 78, 56 ' movl $305419896, (%eax)
  16120 DATA 34, 12
  16130 DATA 5D             ' popl %ebp
  16140 DATA B8, F0,DE, BC  ' movl $-1698898192, %eax
  16150 DATA 9A
  16160 DATA C3             ' ret
  16170 DATA xx             ' End of code 
  20000 '
  20010 ' arm
  20020 '
  20030 DATA 0D, C0, A0, E1 ' mov       ip, sp
  20040 DATA 00, D8, 2D, E9 ' stmfd      sp!, {fp, ip, lr, pc}
  20050 DATA 04, B0, 4C, E2 ' sub        fp, ip, #4
  20060 DATA 00, C0, A0, E3 ' mov        ip, #0
  20070 DATA 0C, 20, A0, E1 ' mov       r2, ip
  20080 DATA 00, 00, 5C, E1 ' cmp ip, r0
  20090 REM data 0A, 00, 00, AA ' bge   .L4
  20100 DATA 04, 00, 00, aa ' bge .L4
  20110                     ' .L6:
  20120 DATA 02, 31, 91, E7 ' ldr        r3, [r1, r2, asl #2]
  20130 DATA 01, 20, 82, E2 ' add        r2, r2, #1
  20140 DATA 00, 00, 52, E1 ' cmp r2, r0
  20150 DATA 03, C0, 8C, E0 ' add        ip, ip, r3
  20160 REM data 05, 00, 00, BA ' blt   .L6
  20170 DATA fa, ff, ff, ba ' blt .L6
  20180                     ' .L4:
  20190 DATA 0C, 00, A0, E1 ' mov        r0, ip
  20200 DATA 00, A8, 1B, E9 ' ldmea      fp, {fp, sp, pc}
  20210                     ' .Lfe1:
  20220 DATA xx             ' End of code
  25000 '
  25010 ' Func 1
  25020 '
  25030 DATA 0D, C0, A0, E1 ' mov ip, sp
  25040 DATA 00, D8, 2D, E9 ' stmfd sp!, {fp, ip, lr, pc}
  25050 DATA 04, B0, 4C, E2 ' sub fp, ip, #4
  25060 DATA 00, 00, 9F, E5 ' ldr r0, .L4
  25070 DATA 00, A8, 1B, E9 ' ldmea fp, {fp, sp, pc}
  25080                     ' .L5:
  25090                     ' .align 2
  25100                     ' .L4:
  25110 DATA 78, 56, 34, 12 ' .word 305419896
  25120 DATA xx             ' End of code
  26000 '
  26010 ' Func 2
  26020 '
  26030 DATA 0D, C0, A0, E1 ' mov ip, sp
  26040 DATA 00, D8, 2D, E9 ' stmfd sp!, {fp, ip, lr, pc}
  26050 DATA 00, 20, 91, E5 ' ldr r2, [r1, #0]
  26060 DATA 0C, 30, 9F, E5 ' ldr r3, .L4
  26070 DATA 0C, 00, 9F, E5 ' ldr r0, .L4+4
  26080 DATA 04, B0, 4C, E2 ' sub fp, ip, #4
  26090 DATA 00, 30, 82, E5 ' str r3, [r2, #0]
  26100 DATA 00, A8, 1B, E9 ' ldmea fp, {fp, sp, pc}
  26110                     ' .L5:
  26120                     ' .align 2
  26130                     ' .L4
  26140 DATA 78, 56, 34, 12 ' .word 305419896
  26150 DATA F0, DE, BC, 9A ' .word -1698898192
  26160 DATA xx             ' End of code
  30000 '
  30010 ' hp pa-risc
  30020 '
  30030 DATA 80, 1A, 60, 20 '           comb,<= %r26,%r0,L$0008
  30040 DATA 34, 1C, 00, 00 '             ldi 0,%r28
  30050                     ' L$0006
  30060 DATA 0F, 28, 10, B4 '           ldws,ma 4(%r25),%r20
  30070 DATA 37, 5A, 3F, FF '           ldo -1(%r26),%r26
  30080 DATA 8F, 40, 3F, E5 '           comib,<> 0,%r26,L$0006
  30090 DATA 0A, 9C, 0A, 1C '           addl %r28,%r20,%r28
  30100                     ' L$0008
  30110 DATA E8, 40, C0, 02 '            bv,n %r0(%r2)
  30120                     ' .EXIT
  30130 DATA 00, 00, 00, 00 ' .PROCEND
  30140 DATA xx             ' End of code
