Program Description: Write an assembly language program to compute: y=(x-4)(x-14
ID: 3664727 • Letter: P
Question
Program Description: Write an assembly language program to compute: y=(x-4)(x-14) for the range 0 x 10, by stepping one by one through the range. During each iteration, print out a message stating the current value of x and the corresponding value of y. Make sure to define the values of the constants 4 and 14 as constants a1 and a2 – the TA may change these values to further test your code. Try to eliminate as many nop instructions as possible and also try to minimize the length of your code. You may run the program using gdb to verify correctness. Make sure to pay close attention to the requirements above. Output Format: For input of x = 0, output y = 56 For input of x = 1, output y = 39 … … For input of x = 10, output y = -24 Requirements: 1. Follow the requirements as described above. 2. Make sure to comment your code. 3. Name your source file ‘lastname2.m’. [It is a .m file rather than a .s file since you will have macro definitions.]
Explanation / Answer
Answer
// lastname2.m
General our requirement is
y = (x-4)(x-14)
Comes under two expressions with multiplications, So we can write as
temp1 : = x -4;
temp2: = x-14;
W: = temp1*temp2;
So we can write in Assembly Language
;File name Save as lastname2.m
section .text
global _start ;must be declared using gcc
_start:
mov a1 4 ; 4 moved into a1 constant
mov a2,14 ; 14 moved into a2 constant
mov ax , 5 ; 5 means user enter value here ax means x ,that is x=5
sub ax ,a1 ; subtract value like x-4 like x – a1(a1 constant)
mov temp1, ax ; ax value like resultant x-4 moved into temp1
mov ax,6 ; 6 means user enter value here ax means x ,that is x = 6
sub ax,a2 ; subtract value like x-14 like x-a2(a2 constant)
mov temp2, ax ; ax value like resultant x-14 like x-a2 moved into temp2
mov ax, temp1 ; temp1 value moved into ax
imul temp2 ; Multiplication done here
mov w, ax ; The resultant value stored in w
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.