8086 Assembly Problem
|
|||
|
Rank: ? (2)
Member #: 25278 |
Hi
I'm taking an 8086 uProcessor course and I'm stuck on a programming question. First let me say that I'm NOT looking for someone to give me the answer - just some hints about what I'm doing wrong would be great. I'm using emu386 with WinXP, for what that's worth. Also keep in mind that so far we've only studied the basic keywords, nothing fancy. I have a feeling I'm doing this the difficult way, but I'm not sure. After previewing this post, the formatting doesn't look right so I removed most of my comments. Here's the problem: "Count the number of bits, in the double word that starts at memory location DS:1234h, that are 1. Place the count in register AL." My code works well up to a count of nine ones. Starting at ten, the count is always minus one. IOW, if there are 9 ones in the word, my code counts 9. If there are ten ones in the word, my code counts nine. If there are eleven ones in the word, my code counts ten, etc. Here's my code (hope this formats right): Code:
Any ideas? radarfxst |
||
|
|||
|
|||
|
Rank: ? (2)
Member #: 25278 |
Sorry, I meant emu8086, not emu386...
- radarfxst |
||
|
|||
|
|||
|
Rank: ? (5)
Member #: 28723 |
hi,
sure this topic is outdated but i was kind of curious if i could solve this problem ( i'm just beginning to learn assembler myself this is my solution ( 16bit assembler, masm version ): .model tiny ;just .com modul .code .startup mov bx,word ptr value ; get the first word of dword call b10_count1 mov bx,word ptr (value+2) ; get the second part of dword call b10_count1 mov al,sum .exit ; examine 1 word at a time b10_count1: mov testw,bx mov bx,1 b10_10: mov ax,testw and ax,bx ; test 1 bit jz b10_20 inc sum ; count the 1's b10_20: shl bx,1 ; set next bit to the left jnz b10_10 ; when bx zero, finished (8000 shl,1 -> 0000 ) ret ; var definitions: testw dw 0 ;temp var for holding 1 word to be examined value dd 0ffffffffh ;dword to be tested sum db 0 end |
||
|
Please login or register to post a reply.