Pregunta

Estoy un poco avergonzado de pedir esto, pero ¿Cómo saco el valor de un byte en ensamblador? Supongamos que tengo el número 62 en el registro AL. Estoy un objetivo 8086. Parece que hay disponibles sólo interrupciones que la salida de su valor ASCII.

Editar Gracias Nick D, que era lo que estaba buscando. Para responder un par de preguntas, en realidad estoy usando un emulador, Emu8086. El código será utilizado en una pequeña aplicación en una fábrica que utiliza equipo antiguo (es decir, es un secreto).

La solución, utilizando Nick D's idea, se ve algo como esto:

compare number, 99
jump if greater to over99Label
compare number, 9
jump if greater to between9and99Label

;if jumps failed, number has one digit
printdigit(number)

between9and99Label:
divide the number by 10
printascii(quotient)
printascii(modulus)
jump to the end

over99Label:
divide the number by 100
printascii(quotient)
store the modulus in the place that between9and99Label sees as input
jump to between9and99Label

the end:
return

y funciona bien para los bytes sin signo:)

¿Fue útil?

Solución

// pseudocode for values < 100
printAscii (AL div 10) + 48
printAscii (AL mod 10) + 48

convertir el valor a una representación de cadena e imprimirla.

Otros consejos

No tengo acceso a un ensamblador en el momento de comprobarlo, y la sintaxis de todos modos variará dependiendo de lo que el ensamblador que está utilizando, pero esto todavía debe transmitir la idea.

FOUR_BITS:
.db '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'

; If ebx need to be preserved do so
push  ebx

; Get the top four bits of al
mov   bl, al
shl   bl, 4

; Convert that into the ASCII hex representation
mov   bl, [FOUR_BITS + bl]

; Use that value as a parameter to your printing routine
push  bl
call  printAscii
pop   bl

; Get the bottom four bits of al
mov   bl, al
and   bl, 0xF

; Convert that into the ASCII hex representation
mov   bl, [FOUR_BITS + bl]

; Use that value as a parameter to your printing routine
push  bl
call  printAscii
pop   bl

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top