Assignment 02_wp_program

advertisement
ASSIGNMENT NO: 02
TITLE: Write an ALP to accept ten 32-bit and 64 bit Hexadecimal numbers from user and store
them in data segment table and display then number.
PROBLEM STATEMENT: Write an ALP to accept ten 32-bit and 64 bit Hexadecimal
numbers from user and store them in data segment table and display then number
THEORY:
Stack manipulation Instruction:
PUSH:
 PUSH decrements the stack pointer (ESP), then transfers the source operand to the top of
stack indicated by ESP. PUSH is often used to place parameters on the stack before
calling a procedure.
 The PUSH instruction operates on memory operands, immediate operands, and register
operands (including segment registers).
POP:
POP (Pop) transfers the word or doubleword at the current top of stack (indicated by ESP) to the
destination operand, and then increments ESP to point to the new top of stack. POP moves
information from the stack to a general register, or to memory.
Algorithm:
Write an ALP to accept ten 32-bit and 64 bit Hexadecimal numbers from user and store them in
data segment table and display then number.
1. Start
2. Display welcome message using sys_write call
3. Display accept ten 32-bit numbers
4. Accept (in temporary buffer)and store (in array) ten 32-bit numbers one by one.
5. Display content of 32-bit array message using sys_write call
6. Display 32-bit array element and newline character repeat for all array elements
7. Display accept ten 64-bit numbers
8. Accept (in temporary buffer) and store (in array) ten 64-bit numbers one by one.
9. Display content of 64-bit array message using sys_write call
10. Display 64-bit array element and newline character repeat for all array elements
11. Display thank you message using sys_write call.
12. Exit using sys_exit call
Conclusion:
Hence we performed assignment to accept and display ten 32-bit and 64-bit numbers.
FAQ:
1. Which register is used as a pointer in stack operation?
2. Explain ‘times’ directive.
3. Explain ‘REP’ prefix.
4.
5.
6.
7.
Explain ‘MOVSB’ instruction.
What is macro?
How macro is declared?
Explain –m option of ld?
;--------Group: A
-------
;------ Assignment No :- 02
;ALP to Accept ten 32bit and 64bit numbers and store them in array
and display the same.
section .data
acc32msg db 10,'Please enter ten 32 bit numbers(8 digits):',10,10
acc32msg_len :equ $-acc32msg
arr32msg db 10,'32-BIT ARRAY CONTENTS ARE::',10
arr32msg_len:equ $-arr32msg
entkeymsg db 10,'Press Enter Key to continue....'
ekey_len:equ $-entkeymsg
acc64msg db 10,'Please enter ten 64 bit numbers(16
digits):',10,10
acc64msg_len :equ $-acc64msg
arr64msg db 10,'64-BIT ARRAY CONTENTS ARE::',10
arr64msg_len:equ $-arr64msg
array32 times 80 db 0
array64 times 160 db 0
nxline db 10
section .bss
num32buff resb 9
n32buff_len:equ $-num32buff
num64buff resb 17
n64buff_len:equ $-num64buff
numcnt resw 1
%macro disp_msg 2
mov eax,04 ;disp/write
mov ebx,01 ;op screen
mov ecx,%1
mov edx,%2
int 80h
%endmacro
%macro readnum 2
mov eax,03
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro
;read
;keyboard
section .text
global _start
_start:
;FOR 32BIT NUMBERS
disp_msg acc32msg,acc32msg_len
mov word [numcnt],0
mov edi,array32
up1:
readnum num32buff,n32buff_len
mov ecx,08h
mov esi,num32buff
rep movsb
; repeat
n
(ecx value) times mov string byte
inc word[numcnt]
cmp word[numcnt],10
jne up1
disp_msg entkeymsg,ekey_len
readnum num32buff,1
disp_msg arr32msg,arr32msg_len
mov ecx,10
mov esi,array32
up2:
push ecx
disp_msg esi,8
add esi,8
disp_msg nxline,1
pop ecx
loop up2
disp_msg entkeymsg,ekey_len
readnum num32buff,1
;FOR 64BIT NUMBERS
disp_msg acc64msg,acc64msg_len
mov word [numcnt],0
mov edi,array64
up3:
readnum num64buff,n64buff_len
mov ecx,16
mov esi,num64buff
rep movsb
inc word[numcnt]
cmp word[numcnt],10
jne up3
disp_msg entkeymsg,ekey_len
readnum num64buff,1
disp_msg arr64msg,arr64msg_len
mov ecx,10
mov esi,array64
up4:
push ecx
disp_msg esi,16
add esi,16
disp_msg nxline,1
pop ecx
loop up4
disp_msg entkeymsg,ekey_len
readnum num64buff,1
mov eax,1 ;terminate
mov ebx,0
int 80h
Please enter ten 32 bit numbers(8 digits):
00000002
00000003
10000001
20000001
11111111
33333333
44444441
00000022
11111133
00220022
Press Enter Key to continue....
32-BIT ARRAY CONTENTS ARE::
00000002
00000003
10000001
20000001
11111111
33333333
44444441
00000022
11111133
00220022
Press Enter Key to continue....
Please enter ten 64 bit numbers(16 digits):
1111111111111111
2222222222222222
3333333333333333
4444444444444444
5555555555555555
0000000000000000
3333333333333333
7777777777777777
0000000011111111
Press Enter Key to continue....
64-BIT ARRAY CONTENTS ARE::
1111111111111111
2222222222222222
3333333333333333
4444444444444444
5555555555555555
0000000000000000
3333333333333333
7777777777777777
0000000011111111
Press Enter Key to continue....
Download