Bueno hace algun tiempo hice esta rutina de un reto que posteo mDrinky en un foro vecino ([Enlace externo eliminado para invitados]), el reto consistia en crear una pirámide con el caracter "*" con una altura no superior a 9.
;#####################################################
;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
Imagen


Saludos
Skype: naker.noventa
Muy bueno Naker90. si quieres optimizarlo podrias ahorrar memoria, no uses tantas variables para almacenar los numeros y usas los registros, ademas son mas rapidos los movimientos de registros.

arregla cuando se le pasa 0 :P

al rato me hago el mio.

gracias sigue asi bro.

saludos
Imagen
Ahi te dejo el mio

;Pink
format PE console
entry Inicio
 
include 'win32a.inc'

section '.data' data readable writeable
sPreg   db "Introdusca El tamaño de la Piramide:",0
sDeb    db "Debe Ingregar un Numero Menor entre 1 y 9!!!",10,0
sCRLF   db 0x0D,0x0A,0
sSpace  db " ",0
sAst    db " *",0
sScan   dd "%d",0

section '.code' code readable executable

Inicio:
jle Pre
Excla:
 ccall   [printf],sDeb
 Pre:
 ccall   [printf],sPreg
 push ebx
 ccall  [scanf],sScan,ebx
 mov ecx,[ebx]
 pop ebx
 xor ecx,0
 jz Excla
 cmp ecx,9
 jg Inicio
        mov ebx,ecx
        Repet:
        push ecx ecx
        Spaces:
        push ecx
        ccall   [printf],sSpace
        pop ecx
        loop Spaces
        pop ecx
        xor ecx,0xFFFFFFFF
        add ecx,ebx
        add ecx,2
        Ast:
        push ecx
        ccall   [printf],sAst
        pop  ecx
        loop Ast
        ccall   [printf],sCRLF
        pop ecx
        loop Repet
        Salir:
        ccall [getchar]
        ccall [getchar]
        stdcall [ExitProcess],0

section '.idata' import data readable

library kernel,'kernel32.dll',\
        msvcrt,'msvcrt.dll'
import  kernel,\
        ExitProcess,'ExitProcess'
import  msvcrt,\
        printf,'printf',\
        getchar,'_fgetchar',\
        scanf,"scanf"


Saludos
Imagen
Pink escribió:Ahi te dejo el mio

;Pink
format PE console
entry Inicio
 
include 'win32a.inc'

section '.data' data readable writeable
sPreg   db "Introdusca El tamaño de la Piramide:",0
sDeb    db "Debe Ingregar un Numero Menor entre 1 y 9!!!",10,0
sCRLF   db 0x0D,0x0A,0
sSpace  db " ",0
sAst    db " *",0
sScan   dd "%d",0

section '.code' code readable executable

Inicio:
jle Pre
Excla:
 ccall   [printf],sDeb
 Pre:
 ccall   [printf],sPreg
 push ebx
 ccall  [scanf],sScan,ebx
 mov ecx,[ebx]
 pop ebx
 xor ecx,0
 jz Excla
 cmp ecx,9
 jg Inicio
        mov ebx,ecx
        Repet:
        push ecx ecx
        Spaces:
        push ecx
        ccall   [printf],sSpace
        pop ecx
        loop Spaces
        pop ecx
        xor ecx,0xFFFFFFFF
        add ecx,ebx
        add ecx,2
        Ast:
        push ecx
        ccall   [printf],sAst
        pop  ecx
        loop Ast
        ccall   [printf],sCRLF
        pop ecx
        loop Repet
        Salir:
        ccall [getchar]
        ccall [getchar]
        stdcall [ExitProcess],0

section '.idata' import data readable

library kernel,'kernel32.dll',\
        msvcrt,'msvcrt.dll'
import  kernel,\
        ExitProcess,'ExitProcess'
import  msvcrt,\
        printf,'printf',\
        getchar,'_fgetchar',\
        scanf,"scanf"


Saludos
indetectables.net
ROOTt_FUD
fuck avs
 
 
Arreglo un coso que se me paso en una cadena lol

;Pink
format PE console
entry Inicio
  
include 'win32a.inc'
 
section '.data' data readable writeable
sPreg   db "Introdusca El tamaño de la Piramide:",0
sDeb    db "Debe Ingregar un Numero  entre 1 y 9!!!",10,0
sCRLF   db 0x0D,0x0A,0
sSpace  db " ",0
sAst    db " *",0
sScan   dd "%d",0
 
section '.code' code readable executable
 
Inicio:
jle Pre
Excla:
 ccall   [printf],sDeb
 Pre:
 ccall   [printf],sPreg
 push ebx
 ccall  [scanf],sScan,ebx
 mov ecx,[ebx]
 pop ebx
 xor ecx,0
 jz Excla
 cmp ecx,9
 jg Inicio
        mov ebx,ecx
        Repet:
        push ecx ecx
        Spaces:
        push ecx
        ccall   [printf],sSpace
        pop ecx
        loop Spaces
        pop ecx
        xor ecx,0xFFFFFFFF
        add ecx,ebx
        add ecx,2
        Ast:
        push ecx
        ccall   [printf],sAst
        pop  ecx
        loop Ast
        ccall   [printf],sCRLF
        pop ecx
        loop Repet
        Salir:
        ccall [getchar]
        ccall [getchar]
        stdcall [ExitProcess],0
 
section '.idata' import data readable
 
library kernel,'kernel32.dll',\
        msvcrt,'msvcrt.dll'
import  kernel,\
        ExitProcess,'ExitProcess'
import  msvcrt,\
        printf,'printf',\
        getchar,'_fgetchar',\
        scanf,"scanf"
Saludos
Imagen
Responder

Volver a “Fuentes”