Skip to content

Instantly share code, notes, and snippets.

@asterwolf
Last active December 9, 2015 19:10
Show Gist options
  • Save asterwolf/15f6bcf0187d8a1e4516 to your computer and use it in GitHub Desktop.
Save asterwolf/15f6bcf0187d8a1e4516 to your computer and use it in GitHub Desktop.
/** For this assignment you will write an assembly language function (in 32-bit
* mode) to manipulate a 2-dimensional array that represents an image. The image
* is a bitmapped image, where (at least for the images we will be working with)
* each pixel is represented by 3 bytes that indicate how much red, green, and
* blue there is at that location.
* @author: Diego Diaz
* Course: COMP B13
* Created on: Dec 4, 2015
* Source File: twoDprocessFloat.s
*/
.globl _multiply2Dfloat
_multiply2Dfloat:
pushl %ebp
movl %esp, %ebp
subl $12, %esp
flds 20(%ebp)
movl 12(%ebp), %eax #stores rows into eax
movl 16(%ebp), %ecx #stores cols into ecx
imull %eax, %ecx #stores rows * cols into ecx
movl 8(%ebp), %edx #stores array in edx
LOOP:
subl $1, %ecx #decrements 1 from array offset
js DONE #if sign flag is set, array is done and jumps to DONE
movzbl (%edx, %ecx), %eax #stores content of array in eax as a long
movl %eax, (%esp)
fild (%esp) #loads the content of the array onto the float stack
fmul %st(1), %st(0) #multiplies to content by the factor and stores in %st
fistpl (%esp) #pops the new value off the floating stack
movl (%esp), %eax #stores the new value in eax
cmpl $256, %eax #compares the new value to 256
jl L2 # if less than 256, jumps to L2 to put in array
movl $255, %eax #if greater than or equals to 256, places 255 instead
L2:
movb %al, (%edx, %ecx)
jmp LOOP
DONE:
leave
ret
@pathawks
Copy link

pathawks commented Dec 4, 2015

Hell yeah.

@craigpanek
Copy link

I like it!
Efficient too!
Mine was a bit longer, less efficient - but a fun program!

@asterwolf
Copy link
Author

Thanks Craig! I fixed my small error. It was fun until I spent 2 hours to find 1 little mistake. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment