Uzair zafar
Sec D
QUESTION NO: 1
Using 2 different loops for upper triangle and lower triangle
Explanation of each step is mentioned in comments
INCLUDE Irvine32.inc
.data
.code
main PROC
mov ecx,5d ; TAKING any number n
mov edx,ecx ;iterator for innet loop
sub edx,1d ;
mov eax,0d
mov ebx,1d ; value to print
L1:
push ecx
; pushing ecx to reserve counter
inc eax
; counter for inner loop
mov ecx,eax ;
L2:
Call DumpRegs ; printing value check ebx for pattern
inc ebx
Loop L2 ;inner loop call
mov ebx,1
pop ecx ; poping back value for outer counter
Loop L1
mov ebx,1d ; setting value for reverse iteration
mov ecx,edx ; settign up counter
L3:
push ecx ; storing ecx value
L4:
Call DumpRegs ; printing value check ebx for pattern
inc ebx
Loop L4
mov ebx,1 ; inner loop call
pop ecx
Loop L3 ; inner loop call
exit
main ENDP
END main
Questtion:2
Takes Ebp and Esp subtract esp from ebp and iterate over them a loop the problem is it
gives some garbade values
INCLUDE Irvine32.inc
.data
.code
PrintStack proc
mov edi,esp ;moving value of eps in edi
mov edx,DWORD PTR SS:[EBP] ;moving value of of ebp in edx
sub edx,esp ;subtracting esp
mov ebx,00000000h
mov ax,dx
mov bl,4
div bl ; gets total no of push
items
PUSH 123h
PUSH 365h
PUSH 325h
values
PUSH 321h
PUSH 321h
PUSH 321h
CALL PrintStack ;
POP EAX ; EAX =321h
POP EAX ; EAX =325h
POP EAX ; EAX =365h
POP EAX ; EAX =123h
exit
main ENDP
END main