Project Hello World
by: burt rosenberg
at: university of miami
date: aug 2019
NAME
hello -- prints "hello, world!\n" to standard out and exits.
SYNOPSIS
hello
DESCRIPION
Prints "hello, world!" to standard out and exits.
HISTORY
Introduced in csc421.181.
For csc421.211, program name and string exactly agrees with the text,
The C Programming Language.
Goals
The goals of this project are:
- To exercise the tools of this course: Ubuntu on Virtual box, Subversion,
the C compiler and Make.
- To understand the test-driven and
agile software
development approaches advocated in this course.
Specific steps
Prepare an Ubuntu development image
- Install Virtual Box.
- Download ubuntu-16.04.6-server-i386.iso,
the ISO (image of a CD or DVD) for ubuntu 16.04.6 server version, 32-bit (i386).
- Install the ISO on a Virtual Box virtual machine.
- Start Virtual Box, select New, and fill out the panel with any name, Linux, Ubuntu 32. (not really important)
- On the next several panels, select: 2G RAM; create virtual hard disk; VDI; dynamic; and 32G.
- You will be returned to the main panel, with the new image "Powered Off". Start it with the green arrow.
- You are prompted for the ISO image. Use the folder icon (small and to the right of the pull down) to navigate
to your image, select and start.
- The purple screens are the Ubuntu installer. Take defaults. Use the TAB if the mouse does not yet work.
- Choose a machine name and a username.
- You will need to TAB (or mouse) choose YES to write the partition and format the filesystem.
No proxy.
- Add Open SSH Server to the packages to install.
Yes to install GRUB.
- Reboot and log in.
- Log into virtual ubuntu image (terminal) and update all software then install needed packages:
Special notes:
- Prepare an Ubuntu development image and log in.
- In the ubuntu virtual machine, use the command line Slack'ed to you to do an initial check out of the
repository ("the repo").
- Create a proj0 directory inside of your folder in csc421.svn.
- Copy all of [repo]/class/proj0 to the proj0 directory of your folder and
make an initial commit.
- Modify the helloworld.c to function as in the above man-page.
- Run the test target of the Makefile until your program
performs accordingly.
- Double check that make test runs without differences.
- Commit for a grade by the due date.
Discussion
The provided hello.c is the template. Please modify to satisfy the test case.
The Makefile provided has the default target to build the binary. The test target
redirects output to the helloworld.out file and then compares the captured output
to the reference output give in helloworld.ref. Differences will be reported. If
the match, the diff program is silent.
The clean target removes build and test products. Never commit products!
Commit only sources (in this project — Makefile, helloworld.c and helloworld.ref).
Points off for committing build products.
See the original program
on page 6 of The C Programming Language, by Kernighan and Ritchie.
Answer
.file "hello.c"
.section .rodata
.LC0:
.string "hello, world!"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $4, %esp
subl $12, %esp
pushl $.LC0
call puts
addl $16, %esp
movl $0, %eax
movl -4(%ebp), %ecx
leave
leal -4(%ecx), %esp
ret
.size main, .-main
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609"
.section .note.GNU-stack,"",@progbits
The answer is in the assembly language off of the i86 install in virtual box,
using the line,
cc -S -fno-asynchronous-unwind-tables hello.c
This is presented as a discussion of how calls work, using the stack
to remember the return address.
The pushl %ebp instruction is the equivalent of,
sub $4,%esp # drop the stack 4 bytes
mov %ebp,(%esp) # move data onto the stack
# (indirect through the SP)
The call puts instruction equivalent is,
pushl %eip
movl puts,%eip
where puts is the address where the puts subroutine starts.
The pushl $.LC0 is how the argument is passed to the subroutine.
Note that the various assembler directives, that declare .LC0 to be the
start adress of a string in a read-only data section.