/* begin assembly stub */
/*
NAME Daniel Pacheco
COURSE  ECE 273
SECTION 001
DATE 09.25.23
FILE dpachec_273_001_2.s
PURPOSE The purpose of this lab is to help us learn how to do 
basic operations in assembly like adding, subtracting, multiplying
dividing, moving, and to store data in memory and registers.
*/
.globl dodiff
.type dodiff, @function 
dodiff:
/* prolog */
pushl %ebp
pushl %ebx
movl %esp, %ebp
/* put code here */
movl digit1, %eax /* moves digit1 into register A */
imull %eax, %eax /* multiples eax by eax */
movl digit2, %ebx /* moves digit2 into register B */
imull %ebx, %ebx /* multiplies %ebx by %ebx */
addl %eax, %ebx /* adds register A to register B and stores it in register B */
movl digit3, %ecx /* moves digit3 into register C */
imull %ecx, %ecx /* multiplies %ecx by %ecx */
subl %ecx, %ebx /* subtracts register C from register B and stores it in register B */
movl %ebx, diff /* moves register B into diff */


/* epilog */ 
movl %ebp, %esp 
popl %ebx
popl %ebp 
ret
.globl dosumprod
.type dosumprod, @function 
dosumprod:
/* prolog */
pushl %ebp
pushl %ebx
movl %esp, %ebp
/* put code here */
movl digit1, %eax /* moves digit1 into eax */
addl digit2, %eax /* adds digit2 to eax and stores it in eax */
addl digit3, %eax/* addes digit3 to eax and stores it in eax */
movl %eax, sum /* moves eax into sum */
movl digit1, %eax /* moves digit1 into eax */
imull digit2, %eax /* multiplies eax by digit2 and stores it in eax */
imull digit3, %eax /* multiplies eax by digit3 and stores it in eax */
movl %eax, product /* moves eax into product */
/* epilog */ movl %ebp, %esp
popl %ebx
popl %ebp 
ret
.globl doremainder
.type doremainder, @function 
doremainder:
/* prolog */
pushl %ebp
pushl %ebx
movl %esp, %ebp
/* put code here */
movl product, %eax /* moves product into eax */
movl sum, %ebx /* moves sum into ebx */
movl $0, %edx /* moves 0 into edx */
divl %ebx /* divides ebx by eax and stores the remainder in edx */
movl %edx, remainder /* moves edx into the remainder*/

/* epilog */ movl %ebp, %esp
popl %ebx
popl %ebp 
ret
/* declare variables here */
.comm digit1, 4
.comm digit2, 4
.comm digit3, 4
.comm diff, 4
.comm sum, 4
.comm product, 4
.comm remainder, 4

/* end assembly stub */

