# Leyes de De Morgan
# http://es.wikipedia.org/wiki/Leyes_de_De_Morgan
#
# nitr0us *noSPAM* 0hday.org
#
# Solo para demostrar, por que me estaba enojando
# que no lo entendia logicamente y tampoco me
# salian los calculos mentalmente :@.
#
# NO SALEN ACENTOS EN ESTA COSA...
#
# $gcc demorgan.s -o demorgan

.section .data
Hdr:	.ascii "Leyes de De Morgan\n*** nitr0us ***\n\n\0"
Msg1:	.ascii "Introduce x: \0"
Msg2:	.ascii "Introduce y: \0"
Morg1:	.ascii "\n%c(x | y) <=> %cx & %cy\n\0"
Morg2:	.ascii "\n%c(x & y) <=> %cx | %cy\n\0"
Fmt1:	.ascii "0x%4X <=> 0x%4X\n\0"
Fmt2:	.ascii "%d"
	.equ	not, 172

.section .text
.globl main
main:
	pushl	$Hdr
	call	printf

/* x */
	pushl	$Msg1
	call	printf

	movl	%esp, %ebp
	subl	$0x4, %esp
	leal	(%ebp), %eax
	pushl	%eax
	pushl	$Fmt2
	call	scanf
	movl	(%ebp), %eax
	movl	%eax, %esi

/* y */
	pushl	$Msg2
	call	printf

	movl	%esp, %ebp
	subl	$0x4, %esp
	leal	(%ebp), %eax
	pushl	%eax
	pushl	$Fmt2
	call	scanf
	movl	(%ebp), %eax
	movl	%eax, %edi

/* De Morgan ~(x | y) <=> ~x & ~y*/
	pushl	$not
	pushl	$not
	pushl	$not
	pushl	$Morg1
	call	printf

	movl	%esi, %ebx	# x
	movl	%edi, %ecx	# y

	orl	%ebx, %ecx
	notl	%ecx
	movl	%ecx, %edx
	notl	%ebx
	movl	%edi, %ecx
	notl	%ecx
	andl	%ebx, %ecx

	pushl	%ecx
	pushl	%edx
	pushl	$Fmt1
	call	printf

/* De Morgan ~(x & y) <=> ~x | ~y*/
	pushl	$not
	pushl	$not
	pushl	$not
	pushl	$Morg2
	call	printf

	movl	%esi, %ebx	# x
	movl	%edi, %ecx	# y

	andl	%ebx, %ecx
	notl	%ecx
	movl	%ecx, %edx
	notl	%ebx
	movl	%edi, %ecx
	notl	%ecx
	orl	%ebx, %ecx

	pushl	%ecx
	pushl	%edx
	pushl	$Fmt1
	call	printf

/* Adios */
	pushl	$0x00
	call	exit

