Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Instrucciones para operar a nivel de bit
#1
Hola, boriel.

¿Hay en zx basic instrucciones o funciones para trabajar a nivel de bit? Las necesito, por ejemplo, para leer el teclado con IN.

Gracias.
Reply
#2
juan Wrote:Hola, boriel.

¿Hay en zx basic instrucciones o funciones para trabajar a nivel de bit? Las necesito, por ejemplo, para leer el teclado con IN.

Gracias.

Hola, Juan.
Pues me vas a matar, porque están previstas, pero no las he programado aún. :oops:

Tienes dos opciones por ahora:
1) Usar divisiones y mutiplicaciones de potencias de 2 (el compilador creo que ya las optimiza).
2) Meter ensamblador en medio del código.

Bueno, también puedes esperar a que las saque. Están previstos los Desplazamientos, BIT, AND, OR y XOR a nivel de BIT de hasta 32 bits. Pero no he tenido tiempo de hacerlo. En cuanto lo tenga te a aviso. Eso sí, estas operaciones no van a ser tan rápidas quizá como en ASM. Pero para lo que quieres hacer yo creo que de sobra.
Reply
#3
No problem. Aislaré las operaciones a nivel de bit en funciones (y me apañaré con operaciones con múltiplos de 2), así, cuando el compilador las implemente, sólo tendré que cambiar estas funciones.

Muchas gracias por contestar.
Reply
#4
juan Wrote:No problem. Aislaré las operaciones a nivel de bit en funciones (y me apañaré con operaciones con múltiplos de 2), así, cuando el compilador las implemente, sólo tendré que cambiar estas funciones.

Muchas gracias por contestar.
Gracias por tu paciencia, Juan.

Ya he comenzado a implementar las funciones bit a bit. De momento empezaré con shr y shl. Te avisaré cuando estén.
Por cierto, bájate la versión 1.0.5, ya que las anteriores tienen fallos que pueden impedir que tu programa compile bien.
Reply
#5
This should be fairly simple to implement for the most part. Certainly for 8 bits:

Code:
FUNCTION FASTCALL bNOT (sentIn as uByte) as uByte
    asm
    CPL
    end asm
END FUNCTION

DIM a as uByte

FOR a=0 to 20
print a,bNOT(a)
next a

Of course I haven't worked out how to drop into asm mode well, because CALL and FASTCALL aren't documented as to where they put their parameters.
It looks like a standard call puts them on the stack, but Boriel's code then plays with the stack pointer, which totally confuses me.

Anyway, 8 bit binary NOT? - One line of asm Smile


For 16 bit function code:

Code:
FUNCTION FASTCALL bNOT (sentIn as uInteger) as uInteger
    asm
    LD a,h
    CPL
    ld h,a
    ld a,l
    CPL
    ld l,a
    end ASM
END FUNCTION

DIM a as uByte

FOR a=0 to 20
print a,bNOT(a)
next a
Reply
#6
Instructions for a binary AND, OR and NOT are in the how-to's section of this forum:

<!-- l --><a class="postlink-local" href="http://www.boriel.com/forum/viewforum.php?f=14">viewforum.php?f=14</a><!-- l -->
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)