NAME: PAMINUS MURUNGI KING’ORI
ADM No: CIT-223-032/2018
COURSE: BSc COMPUTER SCIENCE
UNIT TITLE: ASSEMBLY LANGUAGE PROGRAMMING
UNIT CODE: CSE2321
ASSIGNMENT 1
1.
program numbers;
#include("stdlib.hhf");
static
num:int32; x:int32;
begin numbers;
stdout.put("Enter n: ");
stdin.get(num);
mov(0,ecx);
stdout.put("You Have Entered: ",num,nl);
for(mov(0,eax);eax<=num;add(1,eax)) do
add(eax,ecx);
endfor;
stdout.puti32(ecx);
end numbers;
Sample Input:
Enter n: 4
Output:
You Have Entered: 4
10
2.Binary to hexadecimal program:
program binaryConverter;
var
numDigits: int8;
decimalVal: uns32;
#include("stdlib.hhf")
begin binaryConverter;
stdout.put("Enter no. of digits you want to enter: ");
stdin.get(numDigits);
mov(0,edx);
while( numDigits >0 ) do
stdin.getc();
stdout.put(nl,"Enter binary digit: ");
stdin.getc();
if(al=$30) then
shl(1, edx);
sub(1,numDigits);
endif;
if(al!=$30 && al=$31) then
shl(1, edx);
or( %0000_0000_0000_0000_0000_0000_0000_0001, edx );
sub(1,numDigits);
endif;
if(al!=$30 && al!=$31) then
stdout.put("You entered an invalid character. You can only enter 0's and 1's",nl);
endif;
endwhile;
stdout.put(nl,"The value in Hexadecimal: $",edx,nl);
push( edx ); pop( decimalVal);
stdout.put(nl,"The value in Decimal: ",decimalVal,nl);
end binaryConverter;
Sample input:
Enter no. of digits you want to enter: 3
Enter binary digit: 1
Enter binary digit: 1
Enter binary digit: 1
Output:
The value in Hexadecimal: $0000_0007
The value in Decimal: 7
References:
hla-high-level-assembly-examples/3. binToDecHex.hla at master · hmhamza/hla-high-level-assembly-
examples (github.com)