Need help programing in assembly language

In summary, the conversation is about someone requesting help with programming in assembly language and a specific task of designing a program that counts the number of 0's in each integer in a given data set and displays the value in a designated variable. A possible solution using bit-oriented method is provided.
  • #1
Cathartics
27
0
*****need help programing in assembly language*****

Hi there everyone. I am really new to this assembly language and i don't know how to code this simple programe.. Please help me with this. I would very much appreciate it.. here is the question..



Need to design assembly language programe IA-32 that could find the number of 0's [binary] in each integer in x and put and display the value in y.

.DATA

X SWORD -100,200,300,400,-500
Y BYTE 5 DUP (?)
 
Technology news on Phys.org
  • #2
Bit oriented method:

Assume value in EAX, zero bit count will be in EDX

Code:
        mov     ecx,32
        mov     edx,0
lp0:    rol     eax,1
        cmc
        adc     edx,0
        loop    lp0
 
Last edited:
  • #3


.CODE

MAIN PROC

;Initialize variables
MOV CX,5 ;number of elements in X
MOV BX, OFFSET X ;point to X
MOV DI, OFFSET Y ;point to Y

LOOP1: ;loop for each element in X

MOV AX,[BX] ;load element from X into AX
MOV BL,0 ;initialize counter for 0's

CHECK: ;loop for each bit in binary representation

AND AX,1 ;check if LSB is 0
CMP AX,0 ;compare with 0
JE COUNT ;if LSB is 0, jump to count

NEXTBIT: ;continue to next bit
SHR AX,1 ;shift AX to the right by 1
JNZ CHECK ;if AX is not 0, continue checking

COUNT: ;count the number of 0's
INC BL ;increment counter
SHR AX,1 ;shift AX to the right by 1
JNZ CHECK ;if AX is not 0, continue checking

;store the value of BL in Y
MOV [DI],BL ;move value to Y
INC DI ;increment pointer to Y

;continue to next element in X
ADD BX,2 ;move to next element in X
LOOP LOOP1 ;loop for each element in X

;display the values in Y
MOV CX,5 ;reset counter
MOV DI, OFFSET Y ;point to Y
DISPLAY: ;loop for displaying values in Y
MOV DL,[DI] ;load value from Y into DL
ADD DL,'0' ;convert to ASCII
MOV AH,2 ;print character
INT 21H ;print character
INC DI ;increment pointer to Y
LOOP DISPLAY ;loop for each element in Y

EXIT: ;exit program
MOV AH,4CH ;exit program
INT 21H ;exit program

MAIN ENDP

END MAIN

I understand that learning a new programming language can be challenging, especially when it comes to assembly language. My first recommendation would be to familiarize yourself with the basics of assembly language, such as its syntax and common instructions. This will give you a solid foundation to build upon.

In this particular case, the program you are trying to code involves using bit manipulation to count the number of 0's in each integer in a given array. I suggest breaking down the problem into smaller steps and tackling them one at a time. For example, first
 

1. How can I learn assembly language?

It is recommended to start by learning the basics of computer architecture and how processors work. You can then move on to learning the syntax and instructions of a specific assembly language, and practice by writing simple programs.

2. What are the benefits of programming in assembly language?

Assembly language allows for direct control over hardware resources and can result in highly optimized and efficient programs. It is also useful for low-level programming, such as operating systems and device drivers.

3. What tools do I need to program in assembly language?

You will need an assembler, which converts assembly language code into machine code, and a text editor to write your code. Some IDEs also have support for assembly language programming.

4. Can I use assembly language for any type of project?

While assembly language can be used for a wide range of projects, it is not always the best choice. It is best suited for low-level programming or when performance is critical. Higher level languages may be more appropriate for other types of projects.

5. Are there any resources available for learning assembly language?

Yes, there are many online tutorials, books, and forums dedicated to teaching assembly language. You can also find sample code and practice problems to help improve your skills. Additionally, some universities offer courses on assembly language programming.

Similar threads

  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
4
Replies
122
Views
13K
  • Programming and Computer Science
12
Replies
397
Views
13K
  • Programming and Computer Science
Replies
13
Views
2K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
4
Views
15K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
30
Views
4K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top