assume cs:code,ds:data,ss:stack
data segment
arr dw 1111h,2222h,3333h,4444h,5555h,6666h,7777h,8888h
res db 800 dup(0)
data ends
stack segment
db 100 dup(0)
stack ends
code segment
start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov bx,0
mov cx,8
for:
push ds:arr[bx]
add bx,2
loop for
mov bx,0
mov cx,8
for1:
pop ds:arr[bx]
add bx,2
loop for1
mov ax,4c00h
int 21
code ends
end start
comment*
翻转思路
vector<int>arr = {1,2,3,4,10,20,30,40};
stack<int>stk;
for (int i = 0; i < 8; i++)stk.push(arr[i]);
for (int i = 0; i < 8; i++)arr[i] = stk.top(),stk.pop();
*comment
2. 用动态规划求斐波那契数列
assume cs:code,ds:data,ss:stack
data segment
arr dw 1h,1h,100 dup (0)
res db 800 dup (0)
data ends
stack segment
db 100 dup(0)
stack ends
code segment
start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov bx,4
mov cx,10
for:
mov dx,0
add dx,ds:arr[bx-2]
add dx,ds:arr[bx-4]
mov ds:arr[bx],dx
add bx,2
loop for
mov ax,4c00h
int 21
code ends
end start
comment*
求斐波那契数列
int arr[100] = {1,1};
for (int i = 2; i < 10; i++)
arr[i] = arr[i-1] + arr[i-2];
return arr
*comment