org 100h mov ax, 5 ; set ax to 5. mov bx, 2 ; set bx to 2. jmp calc ; go to 'calc'. back: jmp stop ; go to 'stop'. calc: add ax, bx ; add bx to ax. jmp back ; go 'back'. stop: ret ; return to operating system.
La instrucción básica que transfiere el control a otro punto del programa es JMP. Como puede ver en este ejemplo, JMP puede transferir el control hacia adelante y hacia atrás. Puede saltar a cualquier lugar en el segmento de código actual.
Generalmente, cuando se requiere comparar valores numéricos, se usa la instrucción CMP (hace lo mismo que la instrucción SUB (restar), pero no mantiene el resultado, solo afecta a los indicadores).
EJEMPLO DE INSTRUCCIÓN CMP Y SALTO CONDICIONAL
include "emu8086.inc" org 100h mov al, 25 ; set al to 25. mov bl, 10 ; set bl to 10. cmp al, bl ; compare al - bl. je equal ; jump if al = bl (zf = 1). putc 'n' ; if it gets here, then al <> bl, jmp stop ; so print 'n', and jump to stop. equal: ; if gets here, putc 'y' ; then al = bl, so print 'y'. stop: ret ; gets here no matter what.
No hay comentarios:
Publicar un comentario