ASM

This is my first assessed program in assembly language. I have been working with Visual Studio’s Visual C++ Win32 Console Application and using (_asm) assembly code. Here is what I had to do:

Requirements: Write a program in assembly language which takes an integer input, n, and then reads in that number, n, of values. It will have three counters: pcount, zcount, and ncount which are incremented by 1 when the value read in is positive (>0), zero (=0), or negative (<0) respectively. At the end of the list of numbers, these counter values will be written out.

I didn’t have too much trouble writing the code, once I got my head around what needed to be on the stack, when, it was quite a repetitive task (lots of printf and scanf situations). However, once I began to test my program I ran into some errors…

  1. The first error I found was when I set n = 0. Obviously this meant that when the loop decremented the ECX counter it went to -1 and so it never Reached Zero- the condition for the loop ending.
    • I inserted a jump to the end of the loop body if the input was less than or equal to zero, which solved the issue.
  2. The second error I encountered was when testing the result of entering invalid input. I wanted to check what happened if the user wrote ‘bob’ instead of a numerical value. (For my Java assignments, the specifications have always stated that we can assume that the user will not enter invalid input. As I didn’t see that in this spec., I decided to test it.) What appearred to have happened was that the value wasn’t positive, so when compared to zero it didn’t jg (jump if greater than) to the posroutine, or jl (jump if less than) to the negroutine, but continued to what I’d left as the default, incrementing zcount.
    • To solve this, I inserted a zero routine to make each type of value have a condition and the default be to jump to the end of the loop body without incrementing any counters.
  3. However, I tested it again and got the same result. I then realised that, due to the variable ‘value’ being initialised as equal to zero in the supporting C++ at the beginning of the code, perhaps the zero counter is incremented when the inputted value is invalid.
    • As this is the first assignment I’ve had in assembly, I haven’t had much experience of it. I don’t really know how to approach this issue. I tried not assigning a value to ‘value’ in the C++ but when I placed a watch on it while debugging, I noticed that the default value assigned to it is -858993460, which then increases the ncount instead of the zcount, which isn’t any better.

Obviously, I’m all for thorough testing but when I highlight an error which I don’t know how to fix, I wonder whether it would have been better to lose marks for weak testing than to point out the downfalls in my program without solving them…

Concurrent Processes

Last week (15th March 2017) I handed in my COMP104 Concurrent Processes assignment. (I aim to leave at least five days after the deadline before dicussing assignments online as that is the point at which no more submissions can be made.)

This was a variation of the Dining Philosophers Problem, a common test for concurrency algorithms.

Copyists = Philosophers

Copying & Checking ~ Thinking & Eating (Except have to copy before you can check)

Pencil & Eidograph ~ Chopsticks/Spoons (Except different tool in each hand)

copyists 7 and 0 share pencil 3
1       2                           0
3      4                            1
5      6                            2
copyists 0 and 1 share egraph 0
2         3                         1
4         5                         2
6         7                         3

 

The Copyists had to work in synch until each Copyist had copied and checked 5 drawings.

There were also other restrictions, such as the length of time each copyist took but the details of the assignment are beside the point.

This task was… a rollercoaster

I started off very slowly, always forgetting to take my latest version of the program to labs with me so kind of working on two versions simultaneously (or, some might say, concurrently haha). I then stopped doing any work on it whilst I worked on my COMP106 assignment. When I got back to working on this assignment, at first I struggled to work out how to synchronise the threads but, using a combination of the lecture notes; a sample assignment on the Producer-Consumer problem from previous years; and trial and error…(s, many errors…), I eventually had a working solution which I happily handed in two days early after sorting out the output display. The next day, however, I suddenly realised that Copyists 7, 0, and 1 were all sharing Pencil 0! This didn’t take long to fix but I cannot stress enough how important it is to check for logic errors. Sometimes getting the program to compile in the first place is so difficult that I’m almost afraid to check for logic errors- but, as anyone who has ever played with a Rubik’s Cube is well aware, sometimes the only way to get perfect results is to mess stuff up a bit first.

console output

 

HTML + CSS

I don’t have very much experience of HTML and CSS. I have made mockups of websites a few times using HTML- once when on work experience with Rok Animation, and another time for my A2 Computing Project, and (nerd as I am) probably just for fun too…

But I have never had any particular training in HTML, and I haven’t written any CSS, so I was excited to find that COMP106- Human-Centric Computing- will involve being taught HTML!

I find it a little difficult that many people on my course already have a lot of experience with many things we learn, but I’m a quick learner and it may be better to learn formally from scratch than thinking that I know everything already because I’ve messed around with it and made a website before… I get the impression that, had I ended up at University of Hull rather than Liverpool, I would have actually found it harder to progress as they work in C#, my first (programming) language, whereas here I have retained and built upon my C# knowledge by learning Java too!

Anyway, about to embark upon my first HTML + CSS tutorial, wish me luck!

Assembly Assignment 2

For my second assignment, I again have to use inline assembly code. This time, the program must take input of 6 module marks, compare them, and output the highest mark and for which  module it is. I have been instructed that the marks must be stored in an array. Although this would be simple in a high-level language, determining which registers to use and manipulating the array proved difficult.

Well this is interesting. I went to build the lastest version of my program… and AVG warned me of a Trojan horse called BestMarkComparison.exe found on my PC.

avg detection

I managed to fix this with help from stackexchange (where else?), it was a Visual Studio issue…

This was a while ago… something went wrong with this post so I never published it..

 

Assembly Assignment 1

This is my first assessed program in assembly language. I have been working with Visual Studio’s Visual C++ Win32 Console Application and using (_asm) assembly code. Here is what I had to do:

Requirements: Write a program in assembly language which takes an integer input, n, and then reads in that number, n, of values. It will have three counters: pcount, zcount, and ncount which are incremented by 1 when the value read in is positive (>0), zero (=0), or negative (<0) respectively. At the end of the list of numbers, these counter values will be written out.

I didn’t have too much trouble writing the code, once I got my head around what needed to be on the stack, when, it was quite a repetitive task (lots of printf and scanf situations). However, once I began to test my program I ran into some errors…

  1. The first error I found was when I set n = 0. Obviously this meant that when the loop decremented the ECX counter it went to -1 and so it never Reached Zero- the condition for the loop ending.
    • I inserted a jump to the end of the loop body if the input was less than or equal to zero, which solved the issue.
  2. The second error I encountered was when testing the result of entering invalid input. I wanted to check what happened if the user wrote ‘bob’ instead of a numerical value. (For my Java assignments, the specifications have always stated that we can assume that the user will not enter invalid input. As I didn’t see that in this spec., I decided to test it.) What appearred to have happened was that the value wasn’t positive, so when compared to zero it didn’t jg (jump if greater than) to the posroutine, or jl (jump if less than) to the negroutine, but continued to what I’d left as the default, incrementing zcount.
    • To solve this, I inserted a zero routine to make each type of value have a condition and the default be to jump to the end of the loop body without incrementing any counters.
  3. However, I tested it again and got the same result. I then realised that, due to the variable ‘value’ being initialised as equal to zero in the supporting C++ at the beginning of the code, perhaps the zero counter is incremented when the inputted value is invalid.
    • As this is the first assignment I’ve had in assembly, I haven’t had much experience of it. I don’t really know how to approach this issue. I tried not assigning a value to ‘value’ in the C++ but when I placed a watch on it while debugging, I noticed that the default value assigned to it is -858993460, which then increases the ncount instead of the zcount, which isn’t any better.

Obviously, I’m all for thorough testing but when I highlight an error which I don’t know how to fix, I wonder whether it would have been better to lose marks for weak testing than to point out the downfalls in my program without solving them…

.zips

In my most recent Java assignment I was asked to submit my files as a .zip. As I was in a hurry (see Panic! At the deadline), I did the first thing I could think of- I emailed all of the files to myself with the subject of the email the zip filename I wished to use. This worked very effectively and tbh I was quite pleased with myself…

Screenshot of window asking whether to open or save a .zip

After the deadline, my lecturer sent around an email reminding us to submit a .zip archive file and telling people to use their preferred internet search engine to find out if they didn’t know how to do this. I feel like my hacky way around it was a bit of a cheat if other people are struggling to work out how to use the official compression systems…

Okay, um, I thought I’d see how to do it and I don’t feel at all bad now:

umm

Panic! At the deadline

I had just submitted my .zip of 7 .java files and a .pdf to the University submission system with 10 minutes to spare and breathed a sigh of relief… Seeing as the deadline hadn’t passed, I decided to just check that all of the files still worked correctly, as I have been working on the extended requirements for the last two days but hadn’t checked the standard ones since completing my test cases. It felt a bit unnecessary but for some reason I felt like I should… to my horror the standard requirements threw errors!

Errors thrown on compilation

The Java compiler is your friend.

On opening the specified files, I realised that when I was working on the extended requirements (at 3am) I momentarily strayed into the original files instead of my (very similar) extended versions.

What I had submitted were some half extended half standard nonsense files!

 

I quickly fixed the errors and resubmitted in a .zip with THISONE preceding the filename… hopefully the marker will get the message.