01.05.2013 Views

Estructura de computadores

Estructura de computadores

Estructura de computadores

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CC-BY-SA • PID_00178132 70 Programación en ensamblador (x86-64)<br />

5.3.4. <strong>Estructura</strong> do-while<br />

<strong>Estructura</strong> iterativa controlada por una condición expresada al final:<br />

do {<br />

bloque <strong>de</strong> sentencias que ejecutar<br />

} while (condiciones);<br />

Ejemplo<br />

resultado = 1;<br />

do {<br />

resultado = resultado * num;<br />

num--;<br />

} while (num > 1)<br />

Se pue<strong>de</strong> traducir a lenguaje <strong>de</strong> ensamblador <strong>de</strong> la siguiente manera:<br />

mov rax, 1 ;rax será [resultado]<br />

mov rbx, qword [num] ;Se carga la variable en un registro<br />

while:<br />

imul rax, rbx<br />

<strong>de</strong>c rbx<br />

cmp rbx, 1 ;Se hace la comparación<br />

jg while ;Si se cumple la condición salta a while<br />

mov qword [resultado], rax<br />

mov qword [num], rbx<br />

5.3.5. <strong>Estructura</strong> for<br />

<strong>Estructura</strong> iterativa, que utiliza la or<strong>de</strong>n for:<br />

for (valores iniciales; condiciones; actualización) {<br />

bloque <strong>de</strong> sentencias que ejecutar<br />

}<br />

Ejemplo<br />

resultado=1;<br />

for (i = num; i > 1; i--)<br />

{<br />

resultado=resultado*i;<br />

}<br />

Se pue<strong>de</strong> traducir a lenguaje <strong>de</strong> ensamblador <strong>de</strong> esta manera:<br />

mov rax, 1 ;rax será [resultado]<br />

mov rcx, qword [num] ;rcx será [i] que inicializamos con [num]<br />

for:<br />

cmp rcx, 1 ;Se hace la comparación<br />

jg cierto ;Si se cumple la condición, salta a cierto<br />

jmp fin<br />

cierto:<br />

imul rax,rcx<br />

<strong>de</strong>c rcx<br />

jmp for<br />

fin:<br />

mov qword [resultado], rax<br />

mov qword [i], rcx

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!