Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views3 pages

PAMI Assignment Programs

Uploaded by

cit2230322018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

PAMI Assignment Programs

Uploaded by

cit2230322018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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)

You might also like