;#####################################################
;Coder: Naker90
;Reto de la piramide en ASM: http://www.portalhacker.net/b120/ejercicios-asm/148281/
;FASM
;#####################################################
format PE console
entry Main
Include 'C:\FASM\INCLUDE\WIN32AX.INC'
.data
String1 db 'Introduzca la altura de la piramide: ', 0
String2 db 'ERROR, No se permite una altura superior a 9', 0
Altura dd ?, 0
CRLF db ?, 0
Asteriscos db ' *', 0
Espacio db ' ', 0
CountESP dd ?, 0
CountAST dd ?, 0
CountLine dd 0, 0
Bucle1 dd 0, 0
Bucle2 dd 0, 0
.code
Main:
mov [CRLF], 0xA
push String1
call [Print]
push Altura
call [Get]
sub [Altura], 0x30
cmp [Altura], 9
jg Restart ;Salta si es mayor
mov [CountESP], 10
mov [CountAST], 1
push CRLF
call [Print]
PintarESP:
push Espacio
call [Print]
add [Bucle1], 1
mov eax, [Bucle1]
cmp eax, [CountESP]
je PintarAST
jmp PintarESP
PintarAST:
push Asteriscos
call [Print]
add [Bucle2], 1
mov eax, [Bucle2]
cmp eax, [CountAST]
je Contador
jmp PintarAST
Contador:
push CRLF
call [Print]
sub [CountESP], 1
add [CountAST], 1
add [CountLine], 1
mov eax, [CountLine]
cmp [Altura], eax
je Salir
mov [Bucle1], 0
mov [Bucle2], 0
jmp PintarESP
Restart:
push CRLF
call [Print]
push String2
call [Print]
call [Get]
push CRLF
call [Print]
jmp Main
Salir:
call [Get]
push 0
call [Exit]
data import
library Kernel, 'kernel32.dll', \Msvcrt, 'msvcrt.dll'
import Kernel, \Exit, 'ExitProcess'
import Msvcrt, \Print, 'printf', \Get, 'gets'
end data
Saludos