2. Write an 80x86 assembly language program that reads byte size signed integers from memory and counts the number of zeros. Store this count in memory. End when you get a negative number. (20pts) For example: nums DB 4, 0, 0, 12, 6, 8, 0, 4, -1 count DB 0 after executing the procedure count should be 3 count DB 3.
Hello!
AX, BX , CX and DX are 16 bit general purpose registers.
AX is also called as accumulator. any operation like division and ultiplication the result is stored in accumulator(AX)
We can have have 8 bits by refering X with L or H like AH and AL both are 8 bit registers AX = AH + AL , where H represent Higher byte L represents lower byte.
MOV operand 1, operand 2
In this instruction first operand mush be register(AX,AL,AH,BX...) or memory location([DI],[SI]) , second operand can be immediate data or register or memory location.
Ex:
MOV AX, 0015h
MOV [4000h],12h
DB , DW are directives
Directives are used to store inforamtion in the memory
Here i have taken org 100h the program is utilising after first 2 bytes so now our 1st word starts storing at 102h offset address.
var_name db value1,value2,.......value n
Byte(8bits)
In 8086 you can store the data into memory using variables here var_name is a variable so it will allocate the 1 byte memory to the values
var_name dw value1,value2,.......value n
Word(16bits or 2 bytes)
Here var_name is a variable so it will allocate the 2 bytes memory to the all the values
var_name db ?
This creates a variable with no data assigned to it so use ? when dont have clue store which value in varaible.
NOTE: values can be number or charecters or string
VAR_NAME , var_name both are same, 8086 is not case sensitive
ADD operand 1, opearand 2
This instruction add the operand 1 and operand 2 and result stores back to the operand 1.
In this instruction operand 1 must not be immediate value but it can be a register and memory location.
Operand 2 can be any thing register or memory location or register.
Ex:
ADD Cl , 05h
ADD [SI] , 45h
ADD 78h, AX ; first operand must not be immediate value
ADD [DI],Var1 ; both operands must not be addresses
Procedures:
Procedures helps us in code reusability , its similar to functions sometimes same instructions we need to execute for different data in that situation we can use procedures
SYNTAX :
procedure_name PROC
; code
RET
procedure_name ENDP
LOWER ADDRESS BITS GOES TO LEAST SIGNIFICANT BITS.
HIGHER ADDRESS BITS GOES TO MOST SIGNIFICANT BITS.
When var dw 458Bh the data stores at lower loaction lets take DS:0100h is 8Bh and higher loaction that is DS:0101 is 45h
DIV operand
This instruction divides the value accumulator with opearndand result stores back to the Accumulator.
IF 16 bit
AX stores the Quotient
DX stores the Remainder
AX = AX / operand
IF 8 bit
AL stores the Quotient
AH stores the Remainder
AL = AL / operand
Here operand must be Register or Memory location but not immediate data.
EX:
DIV BH ; AH = AH / BH
DIV [5500h]
DIV 0Ah ; should not use immediate value
JNE main ; if zero flag is 0 then goes to main lable
JMP exit ; jumps to the exit of the code
FIrst how it will store negative values?
ANS: Using 2's complement
Lets take -1
Now lets take it as 1 so binary representaion is 00000001b
1s complement of 1 is 11111110b
2's complements = 1's Complement + 1
1111111110b + 1b = 111111111b = FFh
So EMU8086 stores it as FF ,
LOGIC:
Gets the offset address of nums and stores the address in DI
Then takes the data in that location and compares with 0 , if it is 0 then increments the COUNT
If data is -1 then it will return back to the main program
If data is not -1 then DI gets increased and moves to next adddress and this process gets looped.
CODE:
; COUNTS NUMBER OF ZEROS IN A SIGNED ARRAY
org 100h ; storing of variables starts from 100h
JMP START ; jumps to the START code label
NUMS DB 4,0,0,12,6,8,0,4,-1 ; Array of signed numbers
COUNT DB 0 ; count varibale
START: ; main code starts from here
; calls the subroutine or procedure to calculate zeros in an array
CALL ZEROS
MOV CL,COUNT ; moves the value in count variable to CX
HLT ; Halts the execution
ZEROS PROC ; ZEROS procedure starts from here
MOV DI,offset nums ; Gets the offset address of nums into DI
MAIN:
MOV AL,[DI] ; Moves the data in the location of DI
CMP AL,0h ; Compares the AL with 0
JNE next ; If AL is not 0 then goes to NEXT label
INC COUNT ; If AL is 0 then COUNT gets increment
NEXT:
;
CMP AL,-1 ; Compares AL with -1
JE EXIT ; If AL is -1 then goes to EXIT label
INC DI ; IF AL is not -1 then Increments the location in DI
JMP MAIN ; Jumps to Main code of the procedurw
EXIT:
RET ; Returns back to the main program
ZEROS ENDP ; End of procedure
OUTPUT:
Finally COUNT value is stored in CL register and also in the memory location after FFh
CL = 03 and also 010A h stores value of 3 , as number of ZEROS are 3
Hope this helps and clear.
Please feel free to comment if you have any doubts . If you face any difficulty please let me know i will help you with in few minutes.
I strive to provide the best of my knowledge so please upvote if you like the content.
Thank you!
2. Write an 80x86 assembly language program that reads byte size signed integers from memory and...
please do not copy from previous posted answer 6. Determine the next state and output logic. a. Use combinational logic for next state and output b. Explain if you built a Mealy or Moore machine 2. Write an 80x86 assembly language program that reads byte size signed integers from memory and counts the number of zeros. Store this count in memory. End when you get a negative number. (20 pts) For example: nums DB 4,0,0, 12, 6, 8, 0, 4,-1...
INTEL 80x86 ASSEMBLY LANGUAGE CODE Write a windows32 assembly language program that utilizes a recursive procedure. The main (_MainProc) procedure should: accept, from the user, a positive integer. Guard against non-positive integers being entered using a loop. call the sumseries sub-procedure using the cdecl protocol, receive the results of the sub-procedure, and display the results. The sumseries sub-procedure should: recursively find the sum of the series: 1*2 + 2*3 + 3*4 + ... + i*(i+1) (This is an iterative definition....
Assembly Language////Write a program that read in 10 integers from the user. Save the numbers into an array; reverse the array and display the reversed array. .data arrayInt DWORD 10 DUP(?) Your program consists of 4 procedures: 1. main procedure: call procedures getInput, reverseArray, displayArray 2. getInput procedure: prompt user to enter 10 integer numbers, save the numbers into the memory for the arrayInt 3. reverseArray: reverse arrayInt 4. displayArray: display the reversed array
MARS MIP assembly language quesion Write a program that reads 3 integers, print them, stores them, and add them together and print the result
Complete the following Intel assembly language program which determines whether the byte sized operand stored in memory location 'number' is prime or not. The program will write the value of 0 into the memory location 'answer' if the number is not prime, otherwise the initial value of '1' will be left unmodified (indicating that the number is prime). The program makes use of the DIV instruction to determine the value of quotient and remainder when dividing the number by 2,3,4,......
c# prograaming language 1. write a program that generates 10,000 random integers in the range of 0-9 and them in binary search tree. 2. use any sort algorithm (insertion, bubble, quick...) to display a list of each of the integers and how many times they appear. 3. at last, add ruction to the BinarySearchTree class that count the number of edges in a tree. Write a program that generates 10,000 random integers in the range of 0-9 and store them...
2. Searching a String: Write a MIPS assembly language program to do the following: Read a string and store it in memory. Limit the string length to 100 characters. Then, ask the user to enter a character. Search and count the number of occurrences of the character in the string. The search is not case sensitive. Lowercase and uppercase letters should be equal. Then ask the user to enter a string of two characters. Search and count the number of...
Programming language is C++. 9. Write a program that reads digits and composes them into integers. For example, 123 is read as the characters 1, 2, and 3. The program should output 123 is 1 hundred and 2 tens and 3 ones. The number should be output as an int value Handle numbers with one, two, three, or four digits. Hint: To get the integer value 5 from the character '5' subtract '0' that is, '5'-'0'
This is a Java program Write a program that reads an unspecified number of integers, determines home many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number to 2 decimal places. System.out.println(countPositive); System.out.println(countNegative); System.out.println(total); System.out.printf("%.2f",total * 1.0 / count); Assume inputs are always integer [-912985158, 912985158] and ends with 0. Input 1 2 -1 3...
Please write in Python language. Assignment 5 0 Write a program that reads in integers and then determines whether input value is prime number or not(using for statement) • First input Input number: 18457 yes . Second input Input number: 52 no