C languages Compiling C with Visual Studio LC3 Assignment

```C languages
g g
Compiling C with Visual Studio
`
Please enter an integer between 1 and 9: 4
◦ Power(2,4) = 16
`
`
`
Have to handle n more than 50
St
Store
input
i
t as 2 digit
di it number:
b
35,
35 45
45, 3
3, 15
15…
◦ Ie: 123
123,123,123,123
123 123 123
`
`
2^50 requires more than 50 bits, therefore,
we can not use registers
g
(R0-R7)
(
) to store the
answer, as each register is only 16 bits
&AElig; the answer must be store in memory.
main{
`
Have a subroutine
◦ N2 to double a number
`
`
`
total = 2;
for(i = 1; i &lt; n; i++){
total = n2(total);
}
printf(&quot;2 ^n = total”);
}
int n2(int x){
return x+x;
}
A for loop using BR{nzp}
Have a subroutine to print
result converting from integer to sequence of
characters
To handle different hardness
hardness, only need to
handle n2 subroutine
`
Store like this:
◦
◦
◦
◦
`
`
Every time loop
If sum is over 10
backward
Here is 2^7 = 128
`
`
`
`
`
Using gcc in chaos.cs.auckland.ac.nz
Using gcc in Cygwin (not recommended to
use this year)
Using
U
i
Visual
Vi
l Studio
S di
Other compiler:
http://www thefreecountry com/compilers/c
http://www.thefreecountry.com/compilers/c
pp.shtml
In this course, we prefer to use Microsoft
Visual Studio.
`
Open Visual Studio
`
`
Exercise 1: Write a program to ask for a number and print the number in
base 10, octal and hexadecimal representation.
Exercise 2: (Ex 11.11 from textbook): The function scanf reads in a character
from
the
printf
f
th keyboard
k b
d and
d the
th function
f
ti
i tf prints
i t it out.
t What
Wh t do
d the
th following
f ll i
two statements accomplish?
◦
◦
`
scanf(&quot;%c&quot;, &amp;nextChar);
printf(&quot;%d\n&quot;, nextChar);
E
Exercise
i 3:
3
`
`
`
`
Before submitting you assignment, please try
to compile using Visual Studio.
SHH connection: Putty, SSH
Putty:
`
SSH:
◦ Mirror.cs.auckland.ac.nz ?
`
`
`
After log on, putty will put you inside
UNIXHOME folder
You can go to your G drive by typing “cd ..”
T
Type
““man gcc”” for
f manuals
l off GCC
`
Compile
◦ Gcc –o filename.exe filename.c
`
Run:
◦ ./
/ filename
filename.exe
exe arg1 arg2 arg3
`
Document on Cygwin
◦ http://www.cs.auckland.ac.nz/~bruceh/resources/cygwin/
`