Question

In x86 Assembly Language: Develop a program that uses four signed, global, short variables A, B,...

In x86 Assembly Language:

Develop a program that uses four signed, global, short variables A, B, C, D

Initialize each variable A, B, C, D to a different positive one-digit value

Somehow print the four values in order A B C D, space separated

Print a newline character

Reorder the values in the variables from the order A, B, C, D to B, C, D, A

  • A -> B
  • B -> C
  • C -> D
  • D -> A

Somehow print the four values in order A B C D, space separated

0 0
Add a comment Improve this question Transcribed image text
Answer #1

;How to run:
;> nasm -felf32 <filename>.asm
;> gcc -m32 <filename>.o
;> ./a.out

section .data
   ;declare four signed global variables A, B, C, D
   ;and initialize them with values 4, 7, 1, 5 respectively
   A dw 4
   B dw 7
   C dw 1
   D dw 5
   ;%d format for printf function for printing variables
   var_format db " %d ",0
   ;newline character(10) for printing newline
   newline_format db 10,0
  
section .text
   global main
   extern printf

main:
   ;print A, B, C, D values
   call print_ABCD
   ;print newline character
   call print_newline
   ;copy values of A, B, C, D to registers ax, bx, cx, dx respectively
   mov ax, word[A]
   mov bx, word[B]
   mov cx, word[C]
   mov dx, word[D]
   ;A -> B
   mov word[B], ax
   ;B -> C
   mov word[C], bx
   ;C -> D
   mov word[D], cx
   ;D -> A
   mov word[A], dx
   ;print all A, B, C, D values
   call print_ABCD
   ;print newline
   call print_newline
   ret

print_ABCD:
   ;save previous stack pointer
   push ebp
   mov ebp, esp
  
   ;print A
   pusha
   xor eax, eax
   mov ax, word[A]
   push eax
   push var_format
   call printf
   add esp, 8
   popa
  
   ;print B
   pusha
   xor eax, eax
   mov ax, word[B]
   push eax
   push var_format
   call printf
   add esp, 8
   popa

   ;print C
   pusha
   xor eax, eax
   mov ax, word[C]
   push eax
   push var_format
   call printf
   add esp, 8
   popa

   ;print D
   pusha
   xor eax, eax
   mov ax, word[D]
   push eax
   push var_format
   call printf
   add esp, 8
   popa

   mov esp, ebp
   pop ebp

   ret

print_newline:
   ;save previous stack pointer
   push ebp
   mov ebp, esp
  
   ;print newline character
   pusha
   push newline_format
   call printf
   add esp, 4
   popa

   mov esp, ebp
   pop ebp

   ret

Add a comment
Know the answer?
Add Answer to:
In x86 Assembly Language: Develop a program that uses four signed, global, short variables A, B,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a program in x86 Processor Assembly Language that uses the variables below and only mov...

    write a program in x86 Processor Assembly Language that uses the variables below and only mov instructions to copy the value from Var1 to Var2 reversing the order of the bytes. .data Var1 DWORD 56942145h; reversing means should become 45219456h Var2 DWORD?

  • URGENT HELP NEEDED :( Convert the following C++ program into an x86 assembly language program. Comment...

    URGENT HELP NEEDED :( Convert the following C++ program into an x86 assembly language program. Comment the start of each "code block" that performs one of the listed mathematical calculations. Comments go to the right of the actual code, all starting on the same column. Post ONLY your ASM file here to Blackboard when complete. // Global variables char a = 5; short b = 7; int   c = 11; int   d = 13; // Code int main() {    ...

  • Convert the following assembly language program into a C program: *Update: The variables are initialized, in...

    Convert the following assembly language program into a C program: *Update: The variables are initialized, in lines 4 & 6 of the red assembly language code. Convert the following assembly language program into a C program: *Update: The variables are initialized, in lines 4 & 6 of the red assembly language code. include "p24Hxxxx.inc" global__reset bss: Uninitialized data section: Variables start at location 0x0800 x: .space 2: Allocating space (two bytes) to variable. y: .space 2;Allocating space (two bytes) to...

  • X86 Assembly language lab: TITLE Lab 3: assembly language fundamentals               ;;;;; Q1: Don't...

    X86 Assembly language lab: TITLE Lab 3: assembly language fundamentals               ;;;;; Q1: Don't forget to document your program            ; Name:Yuyan Wang ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the APPROPRIATE places in the file. ;;;;; Hint: the appropriate place is not always right below the question. ;;;;; Q2: Write the directive to bring in the IO library           ;;;;; Q3: Create a constant called MAX and initialize it to 150...

  • MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and...

    MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and print a simple checksum for each string. Make your string long enough to hold 50 characters. Don't forget to leave space for the null byte. Our checksum algorithm will produce a value which you can print with the syscall for printing a character. Stop reading strings when the user enters ".". The syscall to read a string (sycall code 8) adds a newline to...

  • Question: WRITE A PROGRAM IN LC-3 ASSEMBLY LANGUAGE. DO NOT ... WRITE A PROGRAM IN LC-3...

    Question: WRITE A PROGRAM IN LC-3 ASSEMBLY LANGUAGE. DO NOT ... WRITE A PROGRAM IN LC-3 ASSEMBLY LANGUAGE. DO NOT USE PYTHON, JAVA, C or C++ or OTHERS. Your task is to write a program that counts the number of 1 bits of the value stored at location given by Datal. Your program should print the count (in hexadecimal, as it is easier) along with an appropriate heading. Test your program with the following values stored in Datal: a xFFFE...

  • Write a C program that will do the following: 1.Declare four integers variables.   intVar1, intVar2, intVar3,and...

    Write a C program that will do the following: 1.Declare four integers variables.   intVar1, intVar2, intVar3,and intVar4. 2. Initialize intVar1 to the value 4; initialize intVar2to the value 5. 3. Declare four more integer variables. exp1, exp2,exp3, and exp4. 4. Declare a character variable charVar. 5. Assign the value of each expression below to variables exp1and exp2 respectively: exp1= intVar1 + ((5 * intVar2) / (3 * intVar1)); exp2 = intVar1 + (5 * (intVar2 / 3)) * intVar1; 6....

  • Program In Assembly For this part, your MAL program must be in a file named p5b.mal....

    Program In Assembly For this part, your MAL program must be in a file named p5b.mal. It must have at least one function in addition to the main program. For the purposes of Part (b), you may assume the following 1. Any line of text typed by a user has at most 80 characters including the newline character. 2. A whitespace character refers to a space, a tab or the new line character. 3. A word is any sequence of...

  • Write a complete C program that does the following: . o Declare a and b as...

    Write a complete C program that does the following: . o Declare a and b as character variables. Initialize a to this value: 127 o Declare c as an unsigned character variable o Multiply a by 2 and store the result in variable b. o Multiple a by 2 and store the result in variable c. Print the values of a, b, and c. Use the %d specifier in each case. Declare d as an integer variable. Initialize d to...

  • I need help with a code in assembly language MASM (x86)

    write an assembly language (x86) program to input in a string 10 multi-digit integers and displays them in ascending order. Modify the code below to comply with the requirement..model small.stack 100h.datastrg1 DB 'Insert numbers: $'strg2 DB 'Sorted numbers: $'Arr Db 10 dup(?)v dw ?.codemain procmov ax,@datamov ds,axmov ah,9lea dx,strg1int 21hmov dl,0ahmov ah,2int 21h;inputsmov di,0mov cx,10Input_loop:mov ah,1int 21hmov arr[di],almov dl,0ahmov ah,2int 21hinc diloop Input_loopmov v,0sort:mov di,0mov cx,10sub cx,vB:mov al,Arr[di]cmp al,Arr[di+1]jng Cmov al,Arr[di]xchg al,Arr[di+1]mov Arr[di],alc:inc diloop Binc vcmp v,10jne sort;Outputmov ah,9lea dx,strg2int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT