Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7813641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:56:32+00:00 2026-06-02T04:56:32+00:00

I need help with a few pointers to this assignment: The program will return

  • 0

I need help with a few pointers to this assignment: The program will return the total number of occurrences of the sequence of letters “the” in the string. [note: we are looking for the letters “the” not just the word “the”. So you would also be counting the “the” in “there” or “then”, for example.) So I am supposed to first see if its a ‘t’, then if next char is a ‘h’ and ‘e’ after that, if so increment total. I need help with my code. I cant figure out my logic. Any advice on how to do this will help me. Here’s my not finished code so far, my main problem is that my jumps are all being executed even when the first character is clearly a “w” but it executes as if it were a “t”:

#include "stdafx.h"
#include <iostream>

using namespace std;


int main(int argc, char* argv[])
{
//  your properly formatted assembly language data here
char Decl[] = "We hold these truths to be self-evident, that "
              "all men are created equal, that they are "
              "endowed by their Creator with certain "
              "unalienable Rights, that among these are "
              "Life, Liberty and the pursuit of Happiness. "
              "That to secure these rights, Governments are "
              "instituted among Men, deriving their just "
              "powers from the consent of the governed, "
              "That whenever any Form of Government becomes "
              "destructive of these ends, it is the Right of "
              "the People to alter or to abolish it, and to "
              "institute new Government, laying its foundation "
              "on such principles and organizing its powers in "
              "such form, as to them shall seem most likely to "
              "effect their Safety and Happiness. Prudence, "
              "indeed, will dictate that Governments long "
              "established should not be changed for light and "
              "transient causes; and accordingly all epxerience "
              "hath shewn, that mankind are more disposed to "
              "suffer, while evils are sufferable, than to "
              "right themselves by abolishing the forms to "
              "which they are accustomed. But when a long train "
              "of abuses and usurpations, pursuing invariably "
              "the same Object evinces a design to reduce them "
              "under absolute Despotism, it is their right, "
              "it is their duty, to throw off such Government "
              "and to provide new Guards for their future "
              "security. Such has been the patient sufferance "
              "of these Colonies; and such is now the "
              "necessity which constrains them to alter their "
              "former Systems of Government. The history of "
              "the present King of Great Britain is a history "
              "of repeated injuries and usurpations, all "
              "having in direct object the establishment of "
              "an absolute Tyranny over these States. To "
              "prove this, let Facts be submitted to a "
              "candid world. Entered by Thomas Arnol ";

unsigned short int total = 0;

     __asm {
//  your syntatically correct assembly language code here
//  column alignment markers below (to guide you)
//      |       |               |
        cld                     ;set left to right scan
        lea     edi, Decl       ;load offset of string
        mov     ecx, 1649       ;length of string +1
        mov     al, 't'         ;load first character into al to be scanned
more1:
repne   scasb                   ;scan byte by byte
        cmp     ecx, 0          ;see if end of string
        je      skip1           ;dont do any more processing
        jmp     case2

skip1:  cmp     ecx, 0 
        ja      more1

case2:  mov     ebx, ecx        ;how many characters left?
        not     ebx             ;form positive index to string
        add     ebx, 1649       ;and point to letter
        cmp     Decl[ebx+1], 'h'    ;compare next letter
        je      case3
        jmp     more1

case3:  mov     ebx, ecx
        not     ebx
        add     ebx, 1649
        cmp     Decl[ebx+2], 'e'
        je      final1
        jmp     more1

final1: inc     total

    }
    return(0);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:56:35+00:00Added an answer on June 2, 2026 at 4:56 am

    On the very first match (after scasb executes), the following jumps are executed:

    jmp     case2  ; meaning the string is not over
    ...
    je      case3  ; meaning the second char is 'h'
    ...
    je      final1   ; meaning the third character is 'e'
    

    and then the function exits. There’s no outer loop on a match. The jmp more1 line is NOT executed if you have a match – only if the third char after ‘t’ is something other than a ‘e’.

    Seriously, are you even debugging your code? A simple step-through would reveal that much in a jiffy. Visual Studio, e. g. does that, and readily shows registers and expressions with registers in the Watch window.

    EDIT: the logic of calculating ebx to grab the second and third character is completely extraneous. You already have a register that points at the right spot in the string – that’s your edi after scasb. Instead of

    case2:  mov     ebx, ecx        ;how many characters left?
        not     ebx             ;form positive index to string
        add     ebx, 1649       ;and point to letter
        cmp     Decl[ebx+1], 'h'    ;compare next letter
    

    you can do

    case2: cmp [edi], 'h'
    

    and later

    cmp [edi+1], 'e'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help with this Java Program example. This example is from the book
I have been trying out Cassandra and need some help in understanding a few
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
Need help writing a script downloads data from google insight using c# this is
need help regarding USSD Gateway. I have to develop an app, which will directly
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
I need help about URL rewriting for image gallery for site. This is problem,
First of all I am in DESPERATE need of help here PLEASE I will
I do some examples and i need help with one or few errors. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.