Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i=0
while (i<n)
{
if (a==0){
b[i]=c[i]+1;
i++;
a=1;
}
else{
b[i]=c[i+1]+1;
i++;
a=0;
}
}


What I have tried:

.MODEL small
.STACK
.DATA
N db 4h 
c db 1h,2h,3h
b db 1h,2h,3h,4h
.CODE
.STARTUP
MOV CX,00h
mov cl,N 
mov bl,offset c
clc 
addition:
 mov al,bl
 adc al,0h
 clc
 loop1:
  cmp al,0
 je next1
 next1: add al,1
 mov B[di],al
 inc si 
 inc di
 mov al,1

 loop2:
 cmp al,0
 jnz next2
next2: add al,1
 mov B[di],al
 inc si
 inc di
 mov al,0

 loop addition 
 .EXIT
 END
Posted
Updated 21-Feb-17 20:46pm
v2
Comments
OriginalGriff 22-Feb-17 2:02am    
And?
What did it do that you didn't expect, or not do that you did?
What have you tried to find out why?
Use the "Improve question" widget to add information toyour question.
Richard MacCutchan 22-Feb-17 4:28am    
That pseudocode looks more like C. Either way, it is just a matter of taking each step and implementing it in assembler. Not too difficult for a BS student.

1 solution

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900