mirror of
https://github.com/caperren/school_archives.git
synced 2025-11-09 21:51:15 +00:00
Added VERY old code. Very cringy to look at, but hey, we all had to start somewhere...
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
AREA Pointers, CODE, READONLY
|
||||
ENTRY
|
||||
Start ADR r0, List
|
||||
@@ -0,0 +1,17 @@
|
||||
AREA Pointers, CODE, READONLY
|
||||
ENTRY
|
||||
Start
|
||||
ADR r0, Array ;Point to address of array
|
||||
MOV r1, #5 ;Set up a loop counter for array
|
||||
MOV r2, #1 ;Set first val to one so math works
|
||||
MultLoop
|
||||
LDR r3,[r0] ;Put current array value into r3
|
||||
MUL r2,r3,r2 ;Multiply array val by stored product
|
||||
ADD r0,r0,#4 ;Move forward by one array element
|
||||
SUBS r1,r1,#1 ;Decrease loop counter
|
||||
BNE MultLoop ;repeat until all elements added
|
||||
|
||||
;Final value in r2 (0x78 == 120 == 5!)
|
||||
|
||||
Array DCD 1,2,3,4,5 ;Array to hold values
|
||||
END
|
||||
@@ -0,0 +1,32 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
TITLE LoopArrayMultiply (main.asm)
|
||||
;Author: Corwin Perren
|
||||
;Date: 3/13/2014
|
||||
;Description:
|
||||
; This program runs through an array and multiplies each value until all
|
||||
; array elements have been iterated through
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
INCLUDE Irvine32.inc
|
||||
|
||||
.data
|
||||
Array DWORD 1,2,3,4,5 ;Array with five values
|
||||
|
||||
.code
|
||||
|
||||
main PROC
|
||||
cld ;Set direction forward
|
||||
mov esi, OFFSET Array ;Point esi to offset for array
|
||||
mov ecx, LENGTHOF Array ;Set loop counter to length of array
|
||||
mov ebx, 1 ;Set storage reg to 1 so initial multiplication works
|
||||
MultLoop:
|
||||
lodsd ;Load current array value into eax
|
||||
mul ebx ;Multiply eax by ebx
|
||||
mov ebx, eax ;Store result in ebx
|
||||
loop MultLoop ;Loop until array empty
|
||||
mov eax, ebx ;Move final value into eax for printing
|
||||
call WriteDec ;Print to screen
|
||||
call Crlf ;Print line
|
||||
exit ;Exit program
|
||||
main ENDP
|
||||
END main
|
||||
@@ -0,0 +1,30 @@
|
||||
AREA ConstrainProg, CODE, READWRITE
|
||||
ENTRY
|
||||
Start
|
||||
ADR sp, Base ;Point to the base of the stack
|
||||
LDR r0, LowerVal ;Load the lower value into r0
|
||||
LDR r1, UpperVal ;Load the upper value in r1
|
||||
LDR r2, ParamToConstrain ;Load the value to constrain into r2
|
||||
STR r0,[sp,#-4] ;Load r0 onto the stack pointer
|
||||
STR r1,[sp,#-4] ;Load r1 onto the stack pointer
|
||||
STR r2,[sp,#-4] ;Load r2 onto the stack pointer
|
||||
BL Constrain ;Call constrain procedure
|
||||
LDR r2, [sp] ;Load constrained value back into r2
|
||||
;r2 should now contain 2000
|
||||
ADD sp, sp, #8 ;Fix the stack pointer
|
||||
Constrain
|
||||
STR LR, [sp, #-4] ;Store return address
|
||||
LDR r5, [sp, #12] ;Retrieve lower
|
||||
LDR r4, [sp, #8] ;Retrieve upper
|
||||
LDR r3, [sp, #4] ;Retrieve val to constrain
|
||||
CMP r3, r4 ;Check if higher than max
|
||||
LDRHI r3, [sp, #8] ;If so, load max
|
||||
CMP r3, r5 ;Check if lower than min
|
||||
LDRLO r3, [sp, #12] ;If so, load min
|
||||
STR r3, [sp, #4] ;Overwrite constrained val
|
||||
LDR PC, [sp], #4 ;Return from procedure
|
||||
ParamToConstrain DCD 2200 ;Value to constrain
|
||||
UpperVal DCD 2000 ;Value to constrain
|
||||
LowerVal DCD 1000 ;Value to constrain
|
||||
Base DCD 0xAAAAAAAA
|
||||
END
|
||||
@@ -0,0 +1,48 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
TITLE Constrain (main.asm)
|
||||
;Author: Corwin Perren
|
||||
;Date: 3/13/2014
|
||||
;Description:
|
||||
; This program runs passes an argument via stack to a constain function
|
||||
; based off of hobby R/C pulse times (1000-2000 microseconds)
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
INCLUDE Irvine32.inc
|
||||
|
||||
.data
|
||||
ParamToConstrain DWORD 2500 ;;;;Value to constrain
|
||||
UpperVal DWORD 2000 ;;;;Upper limit for constraint
|
||||
LowerVal DWORD 1000 ;;;;Lower limit for constraint
|
||||
.code
|
||||
|
||||
Constrain PROC
|
||||
mov ebp, esp ;;;;Move stack pointer into ebp
|
||||
mov eax, [ebp+4] ;;;;Move the param to constrain into eax
|
||||
cmp eax, [ebp+8] ;;;;Compare param to constrain to upper val
|
||||
jg IsGreater ;;;;If it's greater, jump to isgreater
|
||||
cmp eax, [ebp+12] ;;;;If it's not greater check if it's lower than lower val
|
||||
jg NoChange ;;;;If it's not lower, jump to end of procedure
|
||||
mov eax, [ebp+12] ;;;;If lower, move lower constrain value into eax
|
||||
mov [ebp+4], eax ;;;;Replace value to constrain with eax
|
||||
jmp NoChange ;;;;Just to end of procedure
|
||||
IsGreater:
|
||||
mov eax, [ebp+8] ;;;;If greater, move upper val into eax
|
||||
mov [ebp+4], eax ;;;;Replace value to constrain with eax
|
||||
NoChange:
|
||||
ret ;;;;Return from procedure
|
||||
Constrain ENDP
|
||||
|
||||
main PROC
|
||||
|
||||
MultLoop:
|
||||
push LowerVal ;;;;Push lower constraint to the stack
|
||||
push UpperVal ;;;;Push upper constraint to the stack
|
||||
push ParamToConstrain ;;;;Push value onto the stack
|
||||
call Constrain ;;;;Constrain this value
|
||||
pop eax ;;;;Pop constrained value off the stack
|
||||
add esp, 8 ;;;;Clean up stack
|
||||
call WriteDec ;;;;Write value to screen
|
||||
call Crlf ;;;;Prints a new line
|
||||
exit ;;;;Exits the program
|
||||
main ENDP
|
||||
END main
|
||||
Reference in New Issue
Block a user