Question

In: Computer Science

Hi this is Assembly Language MASM x86 program. Please write it in the language and please...

Hi this is Assembly Language MASM x86 program. Please write it in the language and please explain it with comments thank you

Please answer it I really need help this question was refunded before so please answer. Thank you so much also these are two separate programs thank you.

1) Write a procedure to read in decimal or hex number (byte-sized) Then write a procedure using shifts and ANDS to convert the string to a binary number (if is backward, that ok)

2) Put the first (byte) 10 terms of the Fibonacci series into the byte array FIB 1 1 2 3 5 … Us num1 = 1 and num2 = 1 to start, NO other numbers allowed)

Solutions

Expert Solution

1) The code with detailed comments is given below:

assume cs:code, ds:data

;define data segment
data segment          
    msg1 db "Enter the Hexadecimal number:$" ; message to read a hexadecimal number
    str db 3,0,3 dup(?) ;memory location storing details on the number read
    ; byte sized hexadecimal number can hold 2 hex characters. Hence max size of str is 3 where it can hold
    ; 2 characters with an additional space for enter key.
    msg2 db 10,13,"The binary representation is: $" ; message to display binary representation of the number
data ends

code segment
start:
    mov ax, data
    mov ds, ax ; initialization of data segment
          
    lea dx, msg1 ; display msg1
    mov ah, 09h
    int 21h
  
    lea dx,str ; read the number using buffered input
    mov ah, 0Ah
    int 21h
  
    lea dx, msg2 ; display msg2
    mov ah, 09h
    int 21h
  
    call HexToBin
         
    mov ah, 4ch ; terminate the program
    int 21h  

HexToBin PROC
    mov cl,str+1 ; in case of buffered input, the length of input will be stored at location str+1
    ; cl register holds the length of the string read
    mov ch,00 ; ch stores the value of 0
    lea si,str+2 ; the strating address of the number read is stored in SI index register
    ; The following steps are repeated for every character in the number read
up:
    mov al,[si]; character is read from location memory location pointed to by SI
    ; The ASCII values of Hex numbers can range from 30H to 39H and 41H to 46H
    cmp al,39h; check if ascii value is below or equal to 39h
    ; if the ascii code is <=39H then just and it with 0FH to obtain numbers from 01 to 09H respectively
    jbe next
    ; if ascii value id greater than 39H, then is ranging from A to F
    sub al,07h ; first subtact 7 from it to obtain values in range 3AH to 3FH
    ; then AND it with 0FH to obtain 0AH to 0FH
next:
    and al,0Fh
    ;we would like to have only the 4 digit binary representation for each digit. So the higher order 4 bits is
    ; not necessary
    shl al,4 ; first we shift contents of al left by 4 bit positions to remove the higher order 4 bits     
    mov bl,04; the remaining 4 bits is printed one by one in a loop and bl is loop counter
print:
    mov dl,30h ; dl stores the ascii code of 0
    shl al,1 ; shift left is done to print the binary representation if the proper order.
    ; If reverse representation is required, shift right can be used.
    adc dl,0; the shifted bit will be in the CF; if there is a carry, adc will add 1 to dl else dl will remain 30H
    ; Hence, if there is carry, 1 will be printed on screen and if there is no carry, 0 will be printed on screen
    push ax ; push ax to prevent change in value of al
    mov ah,02h ; print the value in dl on screen
    int 21h
    pop ax ; pop ax will restore value of al
    dec bl ; decrement loop counter
    jnz print; repeat loop until bl is zero
    inc si ; to print next character, increment si pointer    
    loop up ; outer loop continues until cx!=0
    ret
HexToBin ENDP

code ends   
end start

OUTPUT:

2) The program for computing 10 Fibonacci numbers is as follows:

data segment      
    num1 db 1
    num2 db 1
    fib db 10 dup(?)
data ends
code segment
start:
    mov ax, data
    mov ds, ax ; initialize the data segment  
    lea si,fib ; make SI pointer point to the fib byte array
    mov al,num1 ; store num1 as 1st element in fib array
    mov [si],al
    inc si ; increment si to point to next memory location
    ;store num2 as 2nd element in fib array
    mov al,num2
    mov [si],al
    inc si ; incement si pointer
    mov cx,8 ; since two numbers are already stored, 8 more numbers will have to be generated.
up:
    mov al,num1 ; mov num1 to al
    add al,num2 ; add num2 to al
    daa ; convert the result of hexadecimal addition to decimal value by using DAA
    mov [si],al ; store the result in location pointed to bi SI
    ; perform, num1 = num2, num2 = al using register bl
    mov bl,num2
    mov num1,bl
    mov num2,al
    inc si ; increment si pointer
    loop up ; execute the loop until 8 fibonacci numbers are generated.
    mov ah, 4ch ; exit to operating system.
    int 21h  
code ends
end start

OUTPUT:


Related Solutions

Please complete in MASM (x86 assembly language). Use the code below to get started. Use a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a loop with indirect or indexed addressing to reverse the elements of an integer array in place. Do not copy the elements to any other array. Use the SIZEOF, TYPE, and LENGTHOF operators to make the program as flexible as possible if the array size and type should be changed in the future. .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings in locations str1 and str2. Initialize str1 to Computer and initialize str2 to Compater. Assume Str1 holds the correct spelling and str2 may have an incorrect spelling. Use string instructions to check if str2 is correct and if not correct the mistake in str2.
Assembly using x86 irvine (masm) Write a complete program that will input values for num1 ,num2,...
Assembly using x86 irvine (masm) Write a complete program that will input values for num1 ,num2, and num3 and display the value of the expression ( (num1 ^ 3) * num2 + 5 * ( num2 ^ 2) ) / num3. assume that the user enters only numbers that are greater than zero and the calculation never exceed 4 bytes size. Sample run: num1 = 1 num2 = 2 num3 = 3 ((num1 ^ 3) * num2 + 5 *...
Please use assembly language x86 Visual Studio Write a program to add the following word size...
Please use assembly language x86 Visual Studio Write a program to add the following word size numbers:15F2, 9E89, 8342, 99FF, 7130 using adc instruction and a loop. The result must be in DX, AX. Show the result in debug window.
Assembly Language for x86 processors You are to write a program which should first ask for...
Assembly Language for x86 processors You are to write a program which should first ask for 4 random numbers from 0-20 (user will inpute these numbers in no preset order). Input these 5 numbers in variables called num1, num2, num3, num4, and num5. When done, your program should sort these numbers (you will use lots of conditions to check order). num1 should contain smallest number while num5 should contain the biggest. display the contents of num1 through num5 on the...
Write an X86-series assembly language program that checks whether input string is palindrome or not. A...
Write an X86-series assembly language program that checks whether input string is palindrome or not. A palindrome is a word, number, phrase or any other sequence which reads the same backward as forward e.g. madam, racecar. Sample Execution: Please enter a String: redivider The string is a palindrome Another Sample Execution: Please enter a String: abracadabra The string is not a palindrome
Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers...
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
IN ASSEMLY LANGUAGE MASM! please show output run. Write a program that ask the user to...
IN ASSEMLY LANGUAGE MASM! please show output run. Write a program that ask the user to write a string and reverse a string using indirect addressing (may not use the stack - push/pop). The string will be given by the user and be up to 64 characters long. INCLUDE Irvine32.inc INCLUDE macros.inc MAX = 64 .data source BYTE MAX DUP('#'),0 destination BYTE LENGTHOF source DUP('*'),0 actual_length DWORD ? ask BYTE "Enter a String: ",0 .code main proc ; ask user...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the Irvine library for the print function #include <iostream> // The string that needs to be printed char word[] = "Golf\0"; // Pointer to a specific character in the string char * character = word; //NOTE: This main() function is not portable outside of Visual Studio void main() { // Set up a LOOP - See the while loop's conditional expression below int ecx =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT