1a.
The pseudocode described at https://users.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html appears to be an easy standard to understand. Some functions are defined rigorously, but most of the language is loose. Because of that, most of the functions of the language are actually quite powerful. For example, one can get input using "READ input", put out output using "WRITE output". Manipulating data is easy, "WRITE base * multiplier". From what I can tell, arrays aren't natively supported, but you can use WHILE/FOR loops using data.
1b1.
// This encryption technique is incredibly simple, just shifts the input char one up. input=input; output=input + 1;
Phoning it in here of course but this is an encryption technique. A really bad one.
1b2.
// This is going to use C-style pointer syntax because it'll be easier to // implement in ASM. // This is a pretty simple sort function, could be optimized. func sort(lower_bound, upper_bound) { sorted=false; pointer=lower_bound; WHILE NOT sorted WHILE &pointer >= &(pointer + 1) lower=&pointer upper=&(pointer + 1) &pointer=upper &(pointer + 1)=lower pointer=pointer + 1 ENDWHILE pointer=lower_bound; sorted=0; WHILE &pointer <= &(pointer + 1) sorted=sorted + 1; IF sorted EQUAL upper_bound - lower_bound sorted=true ENDIF ENDWHILE IF isint(sorted) sorted=false ENDIF ENDWHILE } // This calls a sort() function, declared above, to sort our array in memory. sort(&first, &last); // To find a mean, we need to add up all members of the array and divide by // the length of the array. If we were using 64-bit non-portable ASM, this // could be sped up using vectorization techniques, but since we're currently // just looking at pseudocode we're just gonna use a WHILE loop. pointer=&first; sum=0 WHILE pointer < &last sum=sum + *pointer; pointer=pointer + 1; ENDWHILE mean=sum / (&last - &first); // Now that we have our memory sorted and our mean figured out, we can loop // through members of the array to find the lower amount of the array to use. pointer=&first; WHILE *pointer < mean pointer=pointer + 1; ENDWHILE lower=allocate_memory(pointer - &first); // Allocate memory for our new array. pointer0=&first; WHILE *pointer0 < mean lower[pointer0 - &first]=*pointer0; ENDWHILE // Now we take the top half of our initial array and copy it inverse into // another array. upper=allocate_memory(&last - pointer); // Allocate memory for upper array. pointer0=&last; WHILE *pointer0 > mean upper[&last - pointer0]=*pointer0; ENDWHILE
1c.
I don't have a local shopping mall, so I'll go through the process for getting to the local Sam's Club.
-
Prepare for launch
-
Acquire keys
- Pick up keys from dresser
- Put keys in pocket
-
Walk out the front door
- Pilot from the dresser to the front door
- Open the front door
- Walk through the front door
-
Turn around:
- Contemplate locking the front door
- OR Lock the front door
-
Sit in car
- Unlock car door
- Open car door
- Sit in driver's seat
-
Start the car
- Push start
-
Acquire keys
- Drivin'
2.
See attached pw1.c source file. Make sure to link with math.c, i.e. gcc -lm pw1.c -o pw1
3.
; AddTwo.asm - adds two 32-bit integers. ; Chapter 3 example .386 .model flat,stdcall .stack 4096 ExitProcess proto,dwExitCode:dword .code main proc mov eax,5 add eax,6 invoke ExitProcess,0 main endp end main
- Pending putting images here, not at a computer that supports all of this. Library at BCC is closed today, should be able to swing something tomorrow.